cpeele00
cpeele00

Reputation: 893

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! Thanks 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);

Upvotes: 0

Views: 711

Answers (2)

Joe
Joe

Reputation: 82614

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.

Upvotes: 1

zsalzbank
zsalzbank

Reputation: 9857

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

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

Upvotes: 3

Related Questions