【发布时间】:2011-02-10 04:20:02
【问题描述】:
好的,我对 jQuery JSON 的东西还很陌生。我正在尝试访问以下 json 输出中的 actions > name 节点。看起来“动作”是“数据”数组中的一个数组。我获取 json 结果的方式可以使用fb.message 正确访问“消息”部分,并且可以使用fb.from.name 访问“来自”下的“名称”节点。那么如何访问“actions”array下的“name”节点呢?
感谢您的帮助!!
代码:
({ "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);
});
【问题讨论】:
标签: jquery arrays json getjson