开发者

How to parse this JSON correctly? Says its property is undefined

I'm trying to parse this json string and it's not working. It's giving me a syntax error in chromes javascript console and firebug. Any help would be greatly appreciate! Than开发者_如何转开发ks much!

"{ "SUCCESS" : false, "DATA" : '', "ERRORS" : [ "duplicate item" ]}"


Uncaught SyntaxError: Unexpected token ILLEGAL

here's my code:

var json = objResponse;
//var obj = JSON.parse(json); //this doesn't work either
var obj = jQuery.parseJSON(json);

alert(obj.SUCCESS);


Your problem is the single quotes (') for DATA.

This helped me out: http://json.parser.online.fr/


Don't mismatch your quotes or your quote types, for example:

'{ "SUCCESS" : false, "DATA" : "", "ERRORS" : [ "duplicate item" ]}'

Will parse just find. An additional note, single quotes are not valid for a JSON string.

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜