javascript - JSON.parse 意外字符错误

我收到此错误:

JSON.parse: unexpected character

当我在 firebug 中运行这条语句时:

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

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

的服务器响应

最佳答案

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

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.

https://stackoverflow.com/questions/8524933/

相关文章:

javascript - 是否有任何可公开访问的 JSON 数据源来测试真实世界的数据?

json - 如何使用标准 Scala 类在 Scala 中解析 JSON?

javascript - 如何使用 html 表单数据发送 JSON 对象

asp.net-mvc - 将 JsonRequestBehavior 设置为 AllowGet 时

javascript - 无法使用 "-"破折号访问 JSON 属性

android - 将 ArrayList 转换为 JSONArray

json - curl json 通过终端向 Rails 应用程序发布请求

sql-server - 在 SQL 中解析 JSON

c# - ASP.NET Core 返回带有状态码的 JSON

python - UnicodeDecodeError : 'utf8' codec can't d