jQuery - JSON 基础知识:每个 ( objJSON ) 不工作。任何解决方案?

jQuery - JSON basics: each( objJSON ) not working. Any solution?

我怎样才能完成这项工作?

objJSON = jQuery.parseJSON(newjson.json);
var j = 0;
var n = objJSON.numberoflevels;

//NOW, THE IMPORTANT PART:
while (j < n) {
    $.each(objJSON.level[j], function (index, item){
        // instructions
    });
    j++;
}

我有一个JSON文档是这样写的:

{
    "numberoflevels": "3",
    "level0": [{
        "name": "1-ONE"
    }],
    "level1": [{
        "name": "1-TWO",
        "parent": "1-ONE"
    }],
    "level2": [{
        "name": "Croc Crocroc",
        "parent": "1-TWO"
    }, {
        "name": "Alan Algomas",
        "parent": "1-TWO"
    }]
}

在那段时间内我想要的是在 each() 中解析我在 JSON

中的所有级别

只需使用简单的 for in

for (key in objJSON) {
  if(key === 'numberoflevels') continue;
  console.log(key + ' command');
}