2013-02-15 47 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