如何从Facebook解码Json响应

时间:2011-09-01 17:52:19

标签: php json facebook

我使用$my_friends = json_decode(file_get_contents($frens));解析了Facebook的JSON响应,print_r($my_friends);给出了以下回复:

    stdClass Object
(
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [name] => Mrinal Kumar Rai Baruah
                    [id] => 546111977
                )

            [1] => stdClass Object
                (
                    [name] => Roshan Khangembam
                    [id] => 553139665
                )

            [2] => stdClass Object
                (
                    [name] => Tarunesh Kumar Saurav
                    [id] => 620690126
                )
.........................
        )

)

我是JSON的新手并且非常困惑。如何迭代上面的响应来获取名称?

1 个答案:

答案 0 :(得分:6)

foreach($my_friends['data'] as $key => $val) {
   echo "Friend #{$key} = {$val['name']}\n";
}