我有一个类似于
的 JSON 对象{
"mydata":[
"one",
"two",
"three"
],
"outside":[
{
"vals":["four", "five", "six"],
"soso":{"seven", "eight", "nine"]
},
{
"vals":["four", "five", "six"],
"soso":{"seven", "eight", "nine"]
},
{
"vals":["four", "five", "six"],
"soso":{"seven", "eight", "nine"]
},
]
"inside":[]
我正在尝试使用 jquery 在“外部”运行 $.each ,这样我就可以从“外部”获取每个 vals 值集,但我没有得到任何东西,但失败得很惨,我放弃了希望有人可以提供帮助
最佳答案
在外部
对象soso
应该看起来像这样
"soso":["七", "八", "九"]
然后
$.each(json.outside, function() {
this.vals.each(function(index, val) {
console.log(val); // output: "four", "five", "six"
});
this.soso.each(function(index, val) {
console.log(val); // output: "seven", "eight", "nine
});
});
关于javascript - 处理 JSON 对象时卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10744661/