I have a json file and I want to display it data using PHP. My below code gives me error,
$json = file_get_contents('data.json');
$data = json_decode($json,true);
$users = $data['devices'];
foreach($users as $user)
{
echo $user['id'];
echo $user['user'];
}
When I replace the 3rd LOC with $users = $data['user']; then it display some data with single alphabet i don't know in which order.
Data.json file contains the following data
{
"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
}
}