我试图访问我的嵌套数组的键和值是这样的:如何访问嵌套的JSON对象键和值
var obj = $.getJSON("mydata.json", function() {
console.log("load success");
});
Object.keys(obj[2].type).forEach(function(key) {
console.log(key, obj[key]);
});
但我得到一个错误。
这里是JSON文件的结构:
{
"nodes": [
{
"nd": "nd1",
"cat": "cat1"
}
],
"links": [
{
"id": 100
}
],
"types": [
{
"type": "one",
"image": "image001"
},
{
"type": "two",
"image": "image002"
},
{
"type": "three",
"image": "image003"
}
]
}
我的目标是获得的值的列表:
一二三
你什么错误? –
'var vals = obj.types.map((x)=> x.image;});' – sed
这个工程对象 – Dimitri