Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing JSON data without quotes with jQuery

Tags:

json

jquery

ajax

I'm trying to parse JSON with jQuery I get from a remote server through AJAX. The JSON data is like: {identifier:"ID", label:"LABEL"} but unable to. Apparently, the field identifier and label has no double quotes. It works when tested on my local test site with double quotes.

Can it be made to work without quotes with jQuery? I have searched around and have found no solutions.

Any input is appreciated. Thanks.

like image 436
BARON'S Avatar asked Dec 12 '22 06:12

BARON'S


1 Answers

Yeah, it's not valid JSON, blahblahblah... like everyone cares if it's valid or not.

At least I don't care, I just want to parse it, so I wrote jsonlite.

with Jsonlite, you can do this:

var s = '{name: jsonlite, birthday: {year: 2013, month: 7, day: 7}, isGreat: true}';
var obj = jsonlite.parse(s);

Which produces exactly the same result as the code below:

var s = '{"name": "jsonlite", "birthday": {"year": 2013, "month": 7, "day": 7}, "isGreat": true}';
var obj = $.parseJSON(s);
like image 135
deerchao Avatar answered Dec 23 '22 07:12

deerchao