I am very new to JSON, stuck in parsing multi level JSON array, I want to parse it using javascript or jquery. From the JSON I want to get application id
, application description
& Product description
[
{
"roadMapData": [
{
"applicationDetail": [
{
"applicationDescr": "R25updated-R25updated",
"applicationId": 352
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 271,
"productSubGroupDes": "TEST123-TEST1234"
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 278,
"productSubGroupDes": "ggg-hhhh"
}
]
}
]
},
{
"roadMapData": [
{
"applicationDetail": [
{
"applicationDescr": "R25updated-R25updated",
"applicationId": 352
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 271,
"productSubGroupDes": "TEST123-TEST1234"
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 278,
"productSubGroupDes": "ggg-hhhh1"
}
]
}
]
}
]
Thanks in advance :)
I am very new to JSON, stuck in parsing multi level JSON array, I want to parse it using javascript or jquery. From the JSON I want to get application id
, application description
& Product description
[
{
"roadMapData": [
{
"applicationDetail": [
{
"applicationDescr": "R25updated-R25updated",
"applicationId": 352
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 271,
"productSubGroupDes": "TEST123-TEST1234"
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 278,
"productSubGroupDes": "ggg-hhhh"
}
]
}
]
},
{
"roadMapData": [
{
"applicationDetail": [
{
"applicationDescr": "R25updated-R25updated",
"applicationId": 352
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 271,
"productSubGroupDes": "TEST123-TEST1234"
}
]
},
{
"productSubGrupDetail": [
{
"productGroupId": 278,
"productSubGroupDes": "ggg-hhhh1"
}
]
}
]
}
]
Thanks in advance :)
Share Improve this question edited Apr 27, 2014 at 12:17 VenomVendor 15.4k13 gold badges68 silver badges97 bronze badges asked Apr 27, 2014 at 12:12 Gaurav GaganGaurav Gagan 591 gold badge1 silver badge10 bronze badges 2- 1 Javascript Multi-level array of JSON objects - how to access key-value pair in second level or higher will help you – Satpal Commented Apr 27, 2014 at 12:17
- It won't works, can you please suggest something more – Gaurav Gagan Commented Apr 27, 2014 at 12:40
2 Answers
Reset to default 3Here is the Demo
Check jQuery.parseJSON
var jsonObj = jQuery.parseJSON(jsonString);
for (i = 0; i < jsonObj.length; i++) {
var roadMapData = jsonObj[i].roadMapData;
var applicationDetail = roadMapData[0].applicationDetail; //First Object
var productSubGrupDetail1 = roadMapData[1].productSubGrupDetail; //Second Object
var productSubGrupDetail2 = roadMapData[2].productSubGrupDetail; //Third Object
console.log(applicationDetail[0].applicationDescr); //applicationDetail's First Object
console.log(productSubGrupDetail1[0].productGroupId); //productSubGrupDetail1's First Object
console.log(productSubGrupDetail2[0].productSubGroupDes); //productSubGrupDetail2's First Object
}
If data initially presented in JSON (as a string), you need first parse it into JavaScript object with JSON.parse(json)
. Then you can access any property with object dot notation. If you are not familiar with objects in JavaScript, check this article.