JSON.parse意外的字符错误 [英] JSON.parse unexpected character error

查看:309
本文介绍了JSON.parse意外的字符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:


JSON.parse:意外字符

JSON.parse: unexpected character

当我在firebug中运行此语句时:

when I run this statement in firebug:

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

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

Why is it so? The JSON string seems correct to me and I also tested it using JSHint. The passed object in the above case is a server response with content type set to application/json

推荐答案

你没有解析一个字符串,你正在解析一个已经解析过的对象:)

You're not parsing a string, you're parsing an already-parsed object :)

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.

这篇关于JSON.parse意外的字符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆