PHP - Parsing JSON file with data in multidimensional object
Posted: 12 Jan 2015, 07:26
I try to parse a JSON file using PHP. The data in this JSON is in a two-dimensional object, like this:
And this is my PHP code:
But because i don't know the names (like John, Klaus) and all available keys and values (like age, count) on beforehand, i think i need to create some foreach loop.
So i appreciate an example for this.
- Thanks in advance.
Code: Select all
{
"John": {
"status":"Wait"
},
"Jennifer": {
"status":"Active"
},
"Klaus": {
"status":"Active",
"age":48,
"count":12,
"progress":0.002989
}
}
Code: Select all
<?php
$string = file_get_contents("/dir/test.json");
$json_a = json_decode($string, true);
echo $json_a['John'][status];
echo $json_a['Jennifer'][status];
So i appreciate an example for this.
- Thanks in advance.