我有一個json文件,我想用PHP顯示它的數據。我下面的代碼給我的錯誤,使用PHP獲取json數據
$json = file_get_contents('data.json');
$data = json_decode($json,true);
$users = $data['devices'];
foreach($users as $user)
{
echo $user['id'];
echo $user['user'];
}
當我更換$users = $data['user'];
第三LOC那麼它顯示的一些數據與單個字母我不以何種順序知道。
Data.json文件包含以下數據
{
"user":
{
"id":"#03B7F72C1A522631",
"user":"[email protected]",
"password":"123",
"email":"[email protected]",
"name":"m",
"creationDate":1385048478,
"compression":true,
"imageProfile":"medium",
"videoProfile":"medium",
"blockAdvert":true,
"blockTracking":true,
"devices":[
{
"id":"#13C73379A7CC2310",
"udid":"cGMtd2luNi4xLV",
"user":"[email protected]",
"creationDate":1385048478,
"status":"active",
},
{
"id":"#FE729556EDD9910D",
"udid":"C1N1",
"user":"[email protected]",
"creationDate":1385291938,
"status":"active",
}]
},
"status":
{
"version":"0.9.5.0",
"command":"getuser",
"opf":"json",
"error":false,
"code":0
}
}
非常感謝你,現在它對我很好用:) – Arif