我想使用json decode获取此数据。请帮助..
到目前为止,我想出了这个脚本,但是我无法在动作下获取倒数第二个和最后一个'name'和'link'。请帮忙..
foreach($json['data'] as $post)
{
$name1 = $post['actions']['name'];
$name2 = $post['actions']['name']['name'];
$name3 = $post['actions']['name']['name']['name'];
但这不起作用请帮助我想从以下示例中获取所有名称和链接数据,这是来自facebook图表api的片段。
{ "data": [ { "actions": [ { "name": "Comment", "link": "http://www.facebook.com/xxxxxidxxxx/posts/xxxxidxxxxxx" }, { "name": "Like", "link": "http://www.facebook.com/xxxxxidxxxxxx/posts/xxxxidxxxxxxx" } { "name": "Comment", "link": "http://www.facebook.com/xxxxxidxxxx/posts/xxxxidxxxxxx" }, { "name": "Like", "link": "http://www.facebook.com/xxxxxidxxxxxx/posts/xxxxidxxxxxxx" } { "name": "Comment", "link": "http://www.facebook.com/xxxxxidxxxx/posts/xxxxidxxxxxx" }, { "name": "Like", "link": "http://www.facebook.com/xxxxxidxxxxxx/posts/xxxxidxxxxxxx" } ],
答案 0 :(得分:0)
请注意actions
是一个数组,它是您data
中唯一的成员。
你只是迭代错误的部分,代码应该是:
foreach($json['data']['actions'] as $action) {
$name = $action['name'];
$link = $action['link'];
}