我有一个 JSON 文件,我需要获取骨灰盒的所有元素;
[
{
"name": "One",
"children": [{
"urn": "urnOne"
}, {
"name": "ChildrenOne",
}
]
}, {
"name": "Two",
"children": [{
"urn": "urnTwo"
}, {
"name": "ChildrenTwo",
}
]
}
]
我的代码无法处理它。
fetch('./viewables.json')
.then(response => ./json.json())
.then(data => {
data.forEach((el, i) => {
data[i].children.urn;
})
});
这里的 children 不是作为对象表示,而是作为数组表示,因此需要指定要引用的序数元素(在本例中为 [0])