我使用$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的新手并且非常困惑。如何迭代上面的响应来获取名称?
答案 0 :(得分:6)
foreach($my_friends['data'] as $key => $val) {
echo "Friend #{$key} = {$val['name']}\n";
}