【问题标题】:Uncaught SyntaxError: Unexpected token eUncaught SyntaxError: Unexpected token e
【发布时间】:2012-08-31 12:27:17
【问题描述】:

我最近遇到了未捕获的语法错误,唯一的补充是从服务器向客户端发送/检索 json 数据。如何调查它是什么?下面是截图

有时我在谷歌浏览器中收到以下错误。

下面是在我们收到此错误之前我最近更新到我的代码的详细信息。

Java 脚本

// Post the topic in the post section
     function  updatePost(xhr, status,jsonData){
                    var args = $.parseJSON(jsonData);

在发送到客户端之前从服务器日志打印的数据

10:20:15,101 INFO  [stdout] (http--127.0.0.1-8080-14)  Printing json data  {

10:20:15,102 INFO  [stdout] (http--127.0.0.1-8080-14)   "topic_username" : "srikanth marni",

10:20:15,102 INFO  [stdout] (http--127.0.0.1-8080-14)   "topic_lstUpdate" : "2012-09-06 10:20:15.025",

10:20:15,103 INFO  [stdout] (http--127.0.0.1-8080-14)   "topic_body" : "Whats up",

10:20:15,104 INFO  [stdout] (http--127.0.0.1-8080-14)   "isValid" : "true"

10:20:15,105 INFO  [stdout] (http--127.0.0.1-8080-14) }

创建 Json 对象的服务器代码

stringWriter = new StringWriter();
                // jfactory.createJsonGenerator(writer, JsonEncoding.UTF8);
                jGenerator = jfactory.createJsonGenerator(stringWriter);

                jGenerator.useDefaultPrettyPrinter();
                jGenerator.writeStartObject(); // {
                jGenerator.writeStringField("topic_username", loginUserName); // "title" : title
                jGenerator.writeStringField("topic_lstUpdate", topicBean.getTopicVO().getLastUpdatedTimestamp().toString());
                jGenerator.writeStringField("topic_body",              topicBean.getTopicVO().getBody());

                jGenerator.writeStringField("isValid", "true");
                jGenerator.writeEndObject(); // }
                jGenerator.close();
                //String jsonData = topicBean.getTopicVO().getBody();
                request.setAttribute("JSON_DATA", stringWriter.toString());
                System.out.println(" Printing json data  " +stringWriter.toString());

                RequestDispatcher rd = servletContext.getRequestDispatcher("/meteor");

Json Parser 错误显示在控制台中

Uncaught SyntaxError: Unexpected token e jquery.js.jsf:16
bF.extend.parseJSON jquery.js.jsf:16
updatePost circle_topic.js.jsf:216
request.onMessage publish_subscribe.js.jsf:56
_f jquery.atmosphere.js.jsf:1975
_invokeFunction jquery.atmosphere.js.jsf:1967
_invokeCallback jquery.atmosphere.js.jsf:2027
AtmosphereRequest.ajaxRequest.onreadystatechange jquery.atmosphere.js.jsf:1438

JSON 数据

Logging message from publish_subsrcibe :{
  "topic_username" : "srikanth marni",
  "topic_lstUpdate" : "2012-09-06 11:52:59.966",
  "topic_body" : "testing",
  "isValid" : "true"
} 

【问题讨论】:

  • 你能把返回的字符串中包含JSON对象吗?
  • @AlbertoLeón 我添加了发送到客户端的 JSON 数据。

标签: jquery json jsf primefaces


【解决方案1】:

这可能有帮助,也可能没有帮助,但是当外部系统调用的处理程序因语法错误而失败时,我也遇到了“意外的令牌 E”错误。

function handleSubsystemResult(text) {
   // Chrome reported "Unexpected token E" here
   var something = JSON.parse(text);  
   ...
}

function main() {
   ...
   callExternSubsystem( "externalSubsystemCode()", handleSubsystemResult );
}

外部子系统代码因语法错误而失败。 Chrome 仅在尝试 JSON.parse() 结果时才报告错误。如果在某种处理程序中调用 JSON.parse(),我会仔细检查是谁调用了该处理程序。

【讨论】:

  • 好答案我也有类似的问题,结果是“JSON.parse(data)”试图处理非对象数据
猜你喜欢
  • 1970-01-01
  • 2012-05-17
  • 2019-02-10
  • 2014-07-08
  • 2011-03-09
  • 2014-01-06
  • 2012-04-10
  • 1970-01-01
相关资源
最近更新 更多