这是我处理 getJSON 响应的 Javascript 代码:
$.getJSON(url, {
userID:userID,
unique:unique
}, function(response) {
alert(JSON.stringify(response));
if(response.connection_status == true) {
alert(response.connected_friends[0].id);
}
});
第一个警报确实触发并给了我这个:
{ "connection_status":true,
"hasResults":true,
"connected_friends":{
"id":"1055",
"name":"My Name"
}
}
为什么我的第二个提醒没有显示?
我在这里缺少什么?
最佳答案
你应该这样做
response.connected_friends["id"]
或
response.connected_friends.id
因为它是一个对象而不是数组
关于javascript - getJSON 响应处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40652894/