0

我有一个看起来类似于的 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 值集,而我什么也没得到,但我失败了,我放弃了希望有人能提供帮助

4

2 回答 2

2

outside对象内soso应如下所示

"soso":["seven", "eight", "nine"]进而

$.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
    });
});
于 2012-05-24T20:22:36.130 回答
1

使用 jQuery:

$.each(jsonObj.outside, function () {
    var i = this; // The current item
});
于 2012-05-24T20:18:44.547 回答