0

我有以下代码

$List2 = json_decode(file_get_contents("https://___URL____&format=json"),true);

以下作品完美

echo '<pre>';print_r($List2);echo '</pre>';

并产生例如

Array
(
[0] => Array
    (
        [uid] => 123456
        [name] => John Williams
        [pic_square] => http://nc4/565228_799523_q.jpg
        [birthday_date] => 07/31/1987
    )

[1] => Array
    (
        [uid] => 123789
        [name] => Jane Thompson
        [pic_square] => http://profile.ak.fbcdn.net/785505233_1702140670_q.jpg
        [birthday_date] => 07/31/1983
    )

[2] => Array
    (
        [uid] => 456789
        [name] => John Gaffney
        [pic_square] => http://profet/hprofile-ak-snc4/3717297628_q.jpg
        [birthday_date] => 07/31/1965
    )

[3] => Array
    (
        [uid] => 987654
        [name] => Johnny Illand
        [pic_square] => http://c4/41766_14329_q.jpg
        [birthday_date] => 07/31/1958
    )

我想运行一个 foreach 以使结果打印得更清楚一些,所以我正在尝试以下操作:

$data = $List2['data'] ;

foreach ($data as $nr => $friends){

echo $friends[name].' - ';

}

但我明白了

Warning: Invalid argument supplied for foreach()

我很难过,这可能很容易!

4

2 回答 2

1

尝试:

foreach ($List2 as $element)
    echo $element[name].' - ';
于 2012-04-24T14:43:54.000 回答
0

在此示例中,“数据”键不存在

$data = $List2;

于 2012-04-24T14:43:06.933 回答