//jsonData:数据集
//destID:目标ID
//json:目标ID结果集
function GetSubJson(jsonData, destID, json) {
for (var i = 0i <jsonData.lengthi++) {
if (jsonData[i].id == destID)
json.push(jsonData[i])
else {
if (jsonData[i].hasOwnProperty("children")) {
GetSubJson(jsonData[i].children, destID, json)
}
}
}
}
//例如
var json = []
GetSubJson(a, "2016", json)
用 for in 循环 遍历
var str = '[{"name":"宗2瓜","num":"1","price":"122"},{"name":"宗呱呱","num":"1","price":"100"}]'var xqo = eval('(' + str + ')')
for(var i in xqo){
alert(xqo[i].name)
}