1
data={"convID":"E40E92FD4B410","serverDate":"2012/06/15 07:51:07 PM","masterInfo":{"instance":"808477149_R_BDD72269D1C1E98A32D8C83EC58CF471","appVersion":"0.97.13.D","depth":4,"jsonURL":"//testtn","scenario":"R","serverDate":"2012/06/15 07:51:07 PM ","deviceName":"M’s","localDate":"2012/5/6 11:14:59 AM PDT"}}

JSON.parse(data);

给出一个错误。这是由 JSON.generate 在 ruby​​ 脚本中生成并发送到节点 http 服务器,应用 decodeURIComponent 来获取上面打印的数据。仍然 JSON 解析失败并出现此错误:

undefined:1
ate":"2012/06/15
^
SyntaxError: Unexpected token d
at Object.parse (native)
4

1 回答 1

3

在您的代码示例data中是 JS 对象。但是JSON.parse将字符串作为其参数,而不是对象。所以你的代码必须是:

data='{"convID":"E40E92FD4B410","serverDate":"2012/06/15 07:51:07 PM","masterInfo":{"instance":"808477149_R_BDD72269D1C1E98A32D8C83EC58CF471","appVersion":"0.97.13.D","depth":4,"jsonURL":"//testtn","scenario":"R","serverDate":"2012/06/15 07:51:07 PM ","deviceName":"M’s","localDate":"2012/5/6 11:14:59 AM PDT"}}';

JSON.parse(data);

因此,请检查data实际代码中变量的值和类型。

于 2012-06-16T03:06:51.600 回答