如何递归解析json? [英] how to parse json recursively ?
本文介绍了如何递归解析json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi
我正在解析json文件。我需要在数组中使用commandList的label属性的所有值。我能够获得label的所有值。但是我只需要commandList标签值我们能得到这个吗?
http://jsfiddle.net/62ryk/1/
Hi
I am parsing the json file .I need all value of label property of commandList in an array .I am able to get all values of label .But I need only commandList label value can we get this ?
http://jsfiddle.net/62ryk/1/
function recursiveIteration(object, callback) {
for (var property in object) {
if (object.hasOwnProperty(property)) {
if (typeof object[property] == "object"){
recursiveIteration(object[property], callback);
}else{
//found a property which is not an object, check for your conditions here
callback(object, property);
}
}
}
}
var labels=new Array();
function test_cb(object, property){
if(property == "label" && object[property])
{
labels.push(object[property])
}
}
recursiveIteration(json, test_cb);
alert(labels)
推荐答案
这篇关于如何递归解析json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文