尝试从返回的 json 对象中提取一些数据。测试时这是我得到的 json 对象。
我正在尝试获取高度,但似乎无法获取。
这里是chrome expression watcher的数据
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);
}
目前我的警报中未定义
最佳答案
JavaScript 中的 For 循环产生键,而不是值。
tester = testData[property][0].height;
关于javascript - 在嵌套的 json 对象中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14902386/