I am trying to decode a json file with php, but it's not displaying anything. The code I have so far:
PHP
$str = file_get_contents('llt_stops.json');
$json = json_decode($str, true);
print_r($json, true);
JSON
{
"stops": [
{
"id": "1",
"name": "Andreaskyrkan",
"locId": "740037195"
},
{
"id": "2",
"name": "Ankarkronan",
"locId": "740037329"
},
{
"id": "3",
"name": "Arcushallen",
"locId": "740037262"
}
]
}
I've also tried with a foreach loop, but it doesn't display anything either.
foreach ($json['stops'] as $field => $value) {
// Use $field and $value here
}
Update: I get this error, don't know whats wrong with the loop:
Invalid argument supplied for foreach()