-3

私はPHPの初心者であり、JSONコンテンツを印刷するのに問題があります

これは私のコードです

//Read text file
$json_data = file_get_contents('data/data.txt');

//Decode it
$obj=json_decode($json_data, true);

//Print array content
print_r($obj);

//Loop the array to write content
foreach( $obj as $Item ){

    // add comment to html list
    echo $Item;
}

私のJSONファイル

[{"name":"ken"}, {"name":"barbie"}]

私の出力

(
    [0] => Array ( [name] => ken )
    [1] => Array ( [name] => barbie )
)
ArrayArray

「ケン」と「バービー」だけを印刷するにはどうすればよいですか?

ありがとう!

4

1 に答える 1

6

変化する

echo $Item;

echo $Item['name'];
于 2012-12-27T14:11:23.590 に答える