我有JSON以下,我想通过javascript迭代它。我该怎么做。
var data= {"key1":[{"alfa":"abcd","a":"a1","b":"b1","c":"c1","d":"d1"},
{"number":"1234","1":"11","22":"2","3":"33","4":"44"}],
"key2":[{"alfa":"abcd","a":"a1","b":"b1","c":"c1","d":"d1"},
{"number":"1234","1":"11","2":"22","3":"33","4":"44"}]}
使用的DS:字符串映射,对象列表
答案 0 :(得分:1)
Object.keys(data).forEach(key => {
for(let item of data[key]){
Object.keys(item).forEach(key => {
console.log(item[key]) // do stuff here
})
}
})
我是这样的
答案 1 :(得分:0)
以下是一些如何访问字段的示例:
console.log(data.key1[0].alfa);
console.log(data.key2[0].alfa);
console.log(data.key2[0].a);