我试图从一个json对象中获取一个特定的字段值,该对象使用javascript ajax调用返回facebook图形api。
我正在尝试使用下面的代码从json对象获取盖字段,但它是不可访问的。表示引用的 http://jsfiddle.net/GD4PC/ her是代码
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 ) {
if(xmlhttp.status == 200){
var ur="https://facebook.com/344128252278047";
var res= JSON.parse(xmlhttp.responseText);
console.log(res);
document.getElementById("myDiv").innerHTML=res.cover;
}
else if(xmlhttp.status == 400) {
alert('There was an error 400')
}
else {
alert('something else other than 200 was returned')
}发布于 2014-07-17 12:37:11
如果您查看res的内容,就会知道cover字段是不可直接访问的。
要访问cover,请尝试以下操作。
res[ur].cover要访问您在评论中提到的source,您应该说
res[ur].cover.source因为您的对象有一个字段"https://facebook.com/344128252278047",它与ur相同。在该字段中有一个字段cover。
https://stackoverflow.com/questions/24803082
复制相似问题