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 に答える