我有一个 JSON 对象数组,如下所示:
[
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" }
]
我想循环它们并在列表中回显它们。我该怎么做?
最佳答案
你的意思是这样的吗?
var a = [
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" }
];
function iter() {
for(var i = 0; i < a.length; ++i) {
var json = a[i];
for(var prop in json) {
alert(json[prop]);
// or myArray.push(json[prop]) or whatever you want
}
}
}
关于javascript - 获取 JSON 对象数组中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1988320/