Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

javascript - JSON.parse意外字符错误(JSON.parse unexpected character error)

I get this error:(我收到此错误:)

JSON.parse: unexpected character(JSON.parse:意外字符) when I run this statement in firebug:(当我在firebug中运行以下语句时:) JSON.parse({"balance":0,"count":0,"time":1323973673061,"firstname":"howard","userId":5383,"localid":1,"freeExpiration":0,"status":false}); Why is it so?(为什么会这样呢?) The JSON string seems correct to me and I also tested it using JSHint.(JSON字符串对我来说似乎是正确的,我也使用JSHint对其进行了测试。) The passed object in the above case is a server response with content type set to application/json(在上述情况下,传递的对象是服务器响应,其内容类型设置为application/json)   ask by krishna translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...