【发布时间】:2014-12-16 21:57:11
【问题描述】:
我正在尝试完成 ReactJS tutorial,但出现此错误“parsererror SyntaxError: Unexpected token a”。
我有带有 get 和 post 方法的 java servlet,我用下一个 json 发送响应:
"[{"author": "Pete Hunt", "text": "This is one comment"}, {"author": "Jordan Walke", "text": "This is another comment"}]"
我也试过这个 {"author": "Pete Hunt", "text": "This is one comment"}, {"author": "Jordan Walke", "text": "This is another comment"}
我看不出问题出在哪里。对我来说,我好像错过了 ReactJS 中的一些东西
UPD 我的 servlet 响应代码。我正在使用 gson 库。
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
ModelObject obj = new ModelObject();
obj.setAuthor("Pete Hunt");
obj.setText("This is one comment");
ModelObject obj2 = new ModelObject();
obj2.setAuthor("Jordan Walke");
obj2.setText("This is *another* comment");
List<ModelObject> objList = new ArrayList<ModelObject>();
objList.add(obj);
objList.add(obj2);
Gson gson = new Gson();
PrintWriter out = response.getWriter();
out.write(gson.toJson(objList));
out.close();
out.flush()
【问题讨论】:
-
删除第一个字符的第一个和最后一个字符(双引号)。
-
我也试过没有它们。
标签: java javascript jquery reactjs