好吧,我相當新的jQuery JSON的東西。我正試圖訪問下面的json輸出中的actions > name
節點。它看起來像「行動」是「數據」數組內的數組。通過使用fb.message
,我可以正確訪問「消息」部分,並且我可以通過fb.from.name
訪問「from」下的「name」節點,從而獲得json結果。那麼我將如何訪問「動作」下的「名稱」節點array?
感謝您的任何幫助!
CODE:對於其他問題
({ "data": [{
"id": "1755670903_1287007912714",
"from": {
"name": "LifeBridge Church",
"id": "1755670903"
},
"message": "Due to weather, church service tomorrow is canceled. See you next week!",
"icon": "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v27562/23/2231777543/app_2_2231777543_9553.gif",
"actions": [
{
"name": "\u0040lifebridgeTX on Twitter",
"link": "http://twitter.com/lifebridgeTX?utm_source=fb&utm_medium=fb&utm_campaign=lifebridgeTX&utm_content=33711605665505280"
}
],
"type": "status",
"application": {
"name": "Twitter",
"id": "2231777543"
},
"created_time": "2011-02-05T02:20:48+0000",
"updated_time": "2011-02-05T02:20:48+0000"
},
{
"id": "1755670903_1281724020620",
"from": {
"name": "LifeBridge Church",
"id": "1755670903"
},
"message": "Service tonight at 5:30... meet us at Eddins Elementary school in McKinney. http://see.sc/8l4Cwo || Praying that God is greatly glorified!",
"icon": "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v27562/23/2231777543/app_2_2231777543_9553.gif",
"actions": [
{
"name": "\u0040lifebridgeTX on Twitter",
"link": "http://twitter.com/lifebridgeTX?utm_source=fb&utm_medium=fb&utm_campaign=lifebridgeTX&utm_content=31388610301272065"
}
],
"type": "status",
"application": {
"name": "Twitter",
"id": "2231777543"
},
"created_time": "2011-01-29T16:30:03+0000",
"updated_time": "2011-01-29T16:30:03+0000"
}]
});
跟進代碼:
$.each(json.data,function(i,fb){
if (!fb.message) continue;
facebookPost += '<li class="ui-li ui-li-static ui-btn-up-c" role="option" data-theme="c">' + fb.message + ' <br /><span class="via">' + fb.created_at + ' via ' + fb.actions[0].name + '</span></li>';
$('#facebookPosts li:first').after(facebookPost);
});
謝謝,這正是我所需要的!此外,如果您碰巧知道......我正在循環訪問數據數組中的所有對象。如果返回undefined,我怎麼能從循環中刪除一個?還是有一個簡單的方法來做到這一點?讓我知道你是否需要代碼示例。 – RyanPitts 2011-02-10 04:33:13