小编典典

JSON.parse意外字符错误

javascript

我收到此错误:

JSON.parse:意外字符

当我在firebug中运行以下语句时:

JSON.parse({"balance":0,"count":0,"time":1323973673061,"firstname":"howard","userId":5383,"localid":1,"freeExpiration":0,"status":false});

为什么会这样呢?JSON字符串对我来说似乎是正确的,我也使用JSHint对其进行了测试。在上述情况下,传递的对象是服务器响应,其内容类型设置为application/json


阅读 339

收藏
2020-05-01

共1个答案

小编典典

您不是在解析字符串,而是在解析一个已经解析的对象:)

var obj1 = JSON.parse('{"creditBalance":0,...,"starStatus":false}');
//                    ^                                          ^
//                    if you want to parse, the input should be a string

var obj2 = {"creditBalance":0,...,"starStatus":false};
// or just use it directly.
2020-05-01