krishna krishna - 1 year ago 115
JSON Question

JSON.parse unexpected character error

I get this error:

JSON.parse: unexpected character

when I run this statement in firebug:


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

Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download