How to parse multilevel json ?
Json format (n-level deep) :
[
{
"attr" : {
"id" : "97987"
},
"children" : [
{
"attr" : {
"id" : "97988"
},
"children" : [
{
"attr" : {
"id" : "97992"
},
"data" : "tag5"
}],
"data" : "tag2"
},
{
"attr" : {
"id" : "97993"
},
"data" : "tag6"
}
],
"data" : "tag1"
},
{
"attr" : {
"id" : "97989",
},
"children" : [
{
"attr" : {
"id" : "97990"
},
"data" : "tag4"
}],
"data" : "tag3"
}
]
for eg. I want to read every children "id".
I have tried $.each
but that allows me to parse fixed number of levels.
You need to use recursion.
Using $.each() and check object or array for each object.
Here's some code. Working code is at http://jsfiddle.net/cwdoh/KKFCZ/