如何从JSON FORMAT打印Facebook好友列表

时间:2014-04-29 17:19:15

标签: php arrays json facebook-graph-api multidimensional-array

我在我的视图文件中使用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

1 个答案:

答案 0 :(得分:0)

试试这个:

foreach($data->friends->data as $friend){
   echo $friend->name." ".$friend->id."<br/>";
}