我在读取 JSON 对象内的数据时有点迷失,这是我拥有的 JSON:
var data = [
{"mes":{
"January":{
"Inversion":"1000","Fans":"1020"}
}
},
{"mes":{
"February":{
"Inversion":"15500","Fans":"285"}
}
}
]
我希望能够打印如下:
1000年1月20日
二月,15500,285
谢谢!
最佳答案
// initialise variable to build output
var out = []
// loop through the array
for(var i=0;i < data.length; i++){
// get a reference to the inner object
var item = data[i].mes
// loop through the inner object (k is the key name)
for(k in item){
// push the built up string onto the output array
out.push(k+", "+item[k].Inversion+", "+item[k].Fans)
}
}
// display the output, joining with newlines
console.log(out.join("\n"))
关于javascript - 我应该如何在 for 循环中使用 JavaScript 访问 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15215058/