我想得到"姓名"来自json数据的值(即xyz,abc,mno,mxc),但由于父节点id不同,我无法解析它。??
"all": {
"id55": {
"Tid": "1",
"Name": "xyz",
"TypeName": "author"
},
"id56": {
"Tid": "2",
"Name": "abc",
"TypeName": "author"
},
"id57": {
"Tid": "3",
"Name": "mno",
"TypeName": "author"
},
"id58": {
"Tid": "4",
"Name": "mzc",
"TypeName": "author"
},
}
答案 0 :(得分:3)
var all = {
"id55": {
"Tid": "1",
"Name": "xyz",
"TypeName": "author"
},
"id56": {
"Tid": "2",
"Name": "abc",
"TypeName": "author"
},
"id57": {
"Tid": "3",
"Name": "mno",
"TypeName": "author"
},
"id58": {
"Tid": "4",
"Name": "mzc",
"TypeName": "author"
}
}
for (var a in all) {
console.log(all[a].Name);
}
<强>输出强>
xyz
abc
mno
mzc
答案 1 :(得分:2)
您可以使用 $.each() 来迭代您的对象并获得Name
值:
$.each(all, function(i,val) {
console.log(all[i].Name);
});
<强> Fiddle Demo 强>