2013-05-26 87 views
0

我下面舉個例子JSON數據:從JSON問題中提取

Array ([data] => Array ([0] => Array ([name] => Jonathan James[id] => 45879) [1] => Array ([name] => Jackson C. Gomez [id] => 989) [2] => Array ([name] => Liz Mack [id] => 787)... etc etc 

我通過它試圖環路和拉的名稱和ID,但沒有返回,這裏是我想要的代碼:

$friendsList = json_decode(file_get_contents('https://graph.facebook.com/'.$fb_user.'/friends?access_token='.$access_token),true); 

foreach ($friendsList as $element){ 

    echo $element[name].' - '.$element[id]; 

} 

我是否必須深入研究JSON,如果是這樣的話?

+1

你確定要做'$ friendsList = $ friendsList [ '數據']'第一? –

+0

@DaveChen Aarrrgghh!史詩失敗了,男生垃圾!謝謝! –

回答

1

請試試這個:

<?php 
$friendsList = array(
    'data' => array(
     array('name' => 'Jonathan James', 'id' => 45879), 
     array('name' => 'Jackson C. Gomez', 'id' => 989), 
     array('name' => 'Liz Mack', 'id' => 787) 
    ) 
); 

foreach ($friendsList['data'] as $element){ 
    echo $element['name'].' - '.$element['id']."<br>\n"; 
} 
?>