I have a JSON file and want to parse value of variable second value in it(I want to get value “Open” in this file JSON..
{“menu”: {
“id”: “file”,
“value”: “File”,
“popup”: {
“menuitem”: [{“value”: “New”, “onclick”: “CreateNewDoc()”},{“value”: “Open”, “onclick”: “OpenDoc()”},{“value”: “Close”, “onclick”: “CloseDoc()”}
]
}
}}
I used code follow to parse but it’s error:
for(var i in itemList)
{
var thisItem = itemList[i];
var itemList1=JSON.parse(thisItem.popup);
for(var j in itemList1)
{
var thisItem1=itemList1[0];
label.text=thisItem1.value;
}
}
Can you help me.!
Here is how u can parse the json. working demo : http://jsfiddle.net/epinapala/B5J5C/3/
The JSON text format is syntactically identical to the code for creating JavaScript objects.
If this is a JSON response from your server , There is no need to parse, you can access the properties of the object directly.
If you are dealing with Json strings instead, use JSON.parse to retreive the Object , and then parse through it. working demo : http://jsfiddle.net/epinapala/B5J5C/2/