我有一個json文件,我想在PHP文件中顯示其數據。我使用下面的代碼,但它給了我錯誤。使用PHP顯示Json數據
$json = file_get_contents('data.json');
$data = json_decode($json);
foreach ($data as $value)
{
echo "$value[1]<br>";
}
data.json文件包含此格式的數據。
{
"users":[
{"id":"03B7F72C1A522631","user":"[email protected]"},
{"id":"27EB9CE8338083AE","user":"[email protected]"},
{"id":"E27854ABBFF8CD92","user":"[email protected]"}],
"status":
{
"version":"0.9.5.0",
"command":"listusers",
"opf":"json",
"error":false,
"code":0
}
}
我想要的輸出
User ID | User Email
03B7F72C1A522631 | [email protected]
27EB9CE8338083AE | [email protected]
'json_decode($ json,tr ue);'如果要用作數組,則添加第二個參數。 –