1

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 :)

VenomVendor
  • 15,064
  • 13
  • 65
  • 96
Gaurav Gagan
  • 59
  • 1
  • 1
  • 10
  • 1
    [Javascript Multi-level array of JSON objects - how to access key-value pair in second level or higher](http://stackoverflow.com/questions/1650090/javascript-multi-level-array-of-json-objects-how-to-access-key-value-pair-in-s) will help you – Satpal Apr 27 '14 at 12:17
  • It won't works, can you please suggest something more – Gaurav Gagan Apr 27 '14 at 12:40

2 Answers2

3

Here 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
}
VenomVendor
  • 15,064
  • 13
  • 65
  • 96
1

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.

Roman Liutikov
  • 1,338
  • 10
  • 17