2013-02-15 81 views
1

嘗試從返回的json對象中提取某些數據。測試這是我得到的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

越來越不確定的for循環中JavaScript產生鍵,而不是值。

tester = testData[property][0].height; 
+1

這曾經讓我所有的時間。 +1爲簡化 – 2013-02-15 20:02:25

-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); 
    } 
} 
+0

我錯過了什麼嗎?請評論爲什麼我得到了downvote,所以我可以從我明顯做出的錯誤中學習。 – 2016-03-16 03:34:02