我在我的视图文件中使用codeigniter
<?php
$app_id = "APP_ID_HERE_XXXXXXXX";
$secret = "SECRET_XXXXXXXX";
$data = file_get_contents('https://graph.facebook.com/me?fields=friends&access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
$data = json_decode($data);
}
?>
问题:如何从JSON数据打印好友列表
解码后的文件数据如下:
stdClass Object
(
[friends] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[name] => frnd_name
[id] => frnd_id
)
[1] => stdClass Object
(
[name] => frnd_name
[id] => frnd_id
)
[2] => stdClass Object
(
[name] => frnd_name
[id] => frnd_id
)....
如何在列表项中打印frnds名称.Thanx
答案 0 :(得分:0)
试试这个:
foreach($data->friends->data as $friend){
echo $friend->name." ".$friend->id."<br/>";
}