Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
[ "name": "Y",
"name": "ravi",
"totalRecords": 30,
"Details": [
{
"Info": "kumar1",
"Number": "123",
"otherDetails": {
"entry": [
{
"class": "class2",
"class": "class3"
},
{
"key": "key2",
"value": "value2"
},
{
"key": "key1",
"value": "value1"
}
]
}
},
{
"Info": "kumar1",
"Number": "123",
"otherDetails": {
"entry": [
{
"class": "class2",
"class": "class3"
},
{
"key": "key2",
"value": "value2"
},
{
"key": "key1",
"value": "value1"
}
]
}
}
]
}
]

What I have tried:

$.each(data,function(key,value){
					 console.log("key = "+key+" value= "+value);
					 $.each(value,function(key1,value1){
							 console.log("key1 = "+key1+" value1= "+value1);
							 $.each(value1,function(key2,value2){
								 console.log("key2 = "+key2+" value2= "+value2);
								}); 
							}); 
							 
					 
				});
Posted
Updated 5-Nov-17 22:29pm
Comments
Karthik_Mahalingam 6-Nov-17 0:07am    
it is not a valid json data
Suvendu Shekhar Giri 6-Nov-17 2:35am    
Yes, Karthik is right (y). The JSON you provided is not a valid JSON entry. Check https://jsonlint.com/ for validating your JSON data.

1 solution

As I provided in the comment section, the JSON data you provided is not a valid JSON entry. One curly brace is missing and there is duplicate entry of key in the JSON data.

I rectified it and did some more check to fulfill what you need. Here is the solution which is working so far :-

<script>
    var jsonData = [{
        "name": "Y",
        "totalRecords": 30,
        "Details": [{
            "Info": "kumar1",
            "Number": "123",
            "otherDetails": {
                "entry": [{
                    "class": "class2"
                },
                    {
                        "key": "key2",
                        "value": "value2"
                    },
                    {
                        "key": "key1",
                        "value": "value1"
                    }
                ]
            }
        },
            {
                "Info": "kumar1",
                "Number": "123",
                "otherDetails": {
                    "entry": [{
                        "class": "class2"
                    },
                        {
                            "key": "key2",
                            "value": "value2"
                        },
                        {
                            "key": "key1",
                            "value": "value1"
                        }
                    ]
                }
            }
        ]
    }];

    $.each(jsonData, function(key, value) {
        console.log("key = " + key + " value= " + value);

        if (typeof value === 'object') {
            $.each(value, function (key1, value1) {
                console.log("key1 = " + key1 + " value1= " + value1);

                if (typeof value1 === 'object') {
                    $.each(value1, function (key2, value2) {
                        console.log("key2 = " + key2 + " value2= " + value2);
                    });
                }
            });
        }
    });
</script>


Note: Let me know if you still finding any issue getting the data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900