1

返されたjsonオブジェクトからデータを取得しようとしています。テスト中にこれは私が取得したjsonオブジェクトです。

高さにアクセスしようとしていますが、取得できないようです。

これがクロームエクスプレッションウォッチャーからのデータです

testData: Object
  10100832561876234: Array[9]
    0: Object
       height: 2048
       source: "https://fbcdn-sphotos-h-a.akamaihd.net"
       width: 1529
       __proto__: Object
    1: Object
    2: Object
    3: Object
    4: Object
    5: Object
    6: Object
    7: Object
    8: Object
    length: 9
    __proto__: Array[0]
10100856101138364: Array[9]
    0: Object
    1: Object
    2: Object
    3: Object
    4: Object
    5: Object
    6: Object
    7: Object
    8: Object
    length: 9

これが高さを取得するための私のコードです

testData = jQuery.parseJSON( jsonData );
for (var property in testData) {
      tester = property[0].height;
      alert(tester);
}

現在、アラートで未定義になっています

4

2 に答える 2

4

JavaScript の for ループは、値ではなくキーを生成します。

tester = testData[property][0].height;
于 2013-02-15T20:00:33.117 に答える
-1

これを試して:

var testData = jQuery.parseJSON( jsonData );
for (var property in testData) {
    if (testData.hasOwnProperty(property)) {
         var tester = testData[property][0].height; // or testData[property].height if that's what you need
      alert(tester);
    }
}
于 2013-02-15T20:01:25.000 に答える