Reputation: 450
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"}}}}';
Upvotes: 0
Views: 744
Reputation: 21
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
Upvotes: 0
Reputation: 1356
You have one missing a {
after NAME_LIST and you should use "
not '
Upvotes: 4
Reputation: 8765
When you use $.parseJSON
you should use " instead of '
if you have any problem with json format. Try jsonformatter
Upvotes: 0
Reputation: 21887
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.
Upvotes: 0