JSON 解析不可能,但 JSON Lint 说可以
我正在使用 jquery 接收几行 javascript 并获取此 err
Unexpected token ILLEGA
这是我正在尝试解析的完整 json。 JSON Lint 不会抱怨...
{
"executionResult": "",
"outputText": "",
"stacktraceText": "groovy.lang.MissingPropertyException: No such property: asfdsf for class: Script1\n at Script1.run(Script1.groovy:1)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.bufferAndPostProcess(ContentBufferingFilter.java:169)\n at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.doFilter(ContentBufferingFilter.java:126)\n at org.sitemesh.config.ConfigurableSiteMeshFilter.doFilter(ConfigurableSiteMeshFilter.java:163)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:366)\n at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)\n at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)\n at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)\n at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at de.hybris.platform.util.RootRequestFilter.doFilter(RootRequestFilter.java:883)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)\n at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)\n at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)\n at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)\n at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\n at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)\n at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)\n at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)\n at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)\n at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396)\n"
}
I am using jquery to receive a few lines of javascript and get this err
Unexpected token ILLEGA
This is the complete json I am trying to parse. JSON Lint does not complain...
{
"executionResult": "",
"outputText": "",
"stacktraceText": "groovy.lang.MissingPropertyException: No such property: asfdsf for class: Script1\n at Script1.run(Script1.groovy:1)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.bufferAndPostProcess(ContentBufferingFilter.java:169)\n at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.doFilter(ContentBufferingFilter.java:126)\n at org.sitemesh.config.ConfigurableSiteMeshFilter.doFilter(ConfigurableSiteMeshFilter.java:163)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:366)\n at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)\n at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)\n at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)\n at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)\n at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at de.hybris.platform.util.RootRequestFilter.doFilter(RootRequestFilter.java:883)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)\n at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)\n at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)\n at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)\n at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\n at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)\n at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)\n at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)\n at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)\n at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396)\n"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 JSON 很好,所以显然您要求 jQuery 解析的内容与您引用的内容不一样,因为 jQuery 是 很高兴解析它。在该示例中,我通过 ajax 加载 JSON 文本。
如果您从 JavaScript string 读取 JSON 文本,而不是从某个地方加载它,例如:
...然后引用您要解析的实际字符串文字,我们可以告诉您有什么问题吗?但那个 JSON 没问题。
Your JSON is fine, so apparently what you're asking jQuery to parse isn't quite what you've quoted, as jQuery is happy to parse it. In that example I'm loading the JSON text via ajax.
If you're reading the JSON text from a JavaScript string rather than by loading it from somewhere, e.g.:
...then quote the actual string literal you're trying to parse, and we can tell you what's wrong with it. But that JSON is fine.
分配给 stacktraceText 的引号内的字符串值是问题所在。 JK的评论一针见血。
您显然正在尝试处理在某处收到的错误消息(异常),该消息不打算以您正在执行的方式进行解析。
如果您可以控制错误消息,则它在 JSON 通常预期的值对上下文中有意义。
The string value inside the quotes assigned to
stacktraceText
is the problem. JK's comment hit the nail on the head.You are clearly trying to deal with an error message (exception) received somewhere that is not intended to be parsed in the way you are doing it.
If you have control of the error message make it make sense in the context of a value pair which is normally expected for JSON.