I am trying to parse this JSON string:
var string = '{"DataSerialized":{"DocumentElement":{"NAME_LIST":"FIELD_1":"VALUE_1","FIELD_2":"VALUE2","FIELD_3":"VALUE_3"}}}}';
how a JSON object how this:
{
"DataSerialized":{
"DocumentElement":{
"NAME_LIST":{
"FIELD_1":"VALUE_1",
"FIELD_2":"VALUE2",
"FIELD_3":"VALUE_3"
}
}
}
}
For that, I tried with jQuery.parseJSON(string) but the result is wrong:
SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 60 of the JSON data
I think that it's a problem with quotes, but I don't know what's wrong exactly
Thanks in advance
SOLUTION:
{ after NAME_LIST
var string = '{"DataSerialized":{"DocumentElement":{"NAME_LIST":{"FIELD_1":"VALUE_1","FIELD_2":"VALUE2","FIELD_3":"VALUE_3"}}}}';
-
2JSON uses double not single quotes. jsonlint.comepascarello– epascarello2014年10月20日 14:38:31 +00:00Commented Oct 20, 2014 at 14:38
-
1your JSON is invalid, you have an extra closing curly brace.inorganik– inorganik2014年10月20日 14:39:13 +00:00Commented Oct 20, 2014 at 14:39
4 Answers 4
You have one missing a { after NAME_LIST and you should use " not '
This string:
var string = "{'DataSerialized':{'DocumentElement':
{'NAME_LIST':'FIELD_1':'VALUE_1','FIELD_2':'VALUE2','FIELD_3':'VALUE_3'}}}}";
Has one too many closing braces.
Comments
When you use $.parseJSON you should use " instead of '
if you have any problem with json format. Try jsonformatter
1 Comment
You have a wrong JSON format, you miss one { after name list. There is correct example
var string = '{"DataSerialized":{"DocumentElement":{"NAME_LIST":{"FIELD_1":"VALUE_1","FIELD_2":"VALUE2","FIELD_3":"VALUE_3"}}}}';
JSON.parse(string);
Try to run it on browser dev console and then you will see correct object