I have been banging my head against a brick wall the past few days trying to figure this out after reading so many tutorial and forum post but I still can't figure it out. I would be very grateful if someone could help me out.
Basically I am being supplied with this JSON Data structure:
Code: Select all
$json='{
"countries": {
"country": [
{
"@attributes": {
"Name": "Germany",
"Lat": "52.6847077739394",
"Lng": "-6.81976318359375",
"ZoomLevel": "7"
}
},
{
"@attributes": {
"Name": "Sweeden",
"Lat": "54.00131186464818",
"Lng": "-7.36358642578125",
"ZoomLevel": "8"
}
}
]
}
}';
Code: Select all
$json_array=json_decode($json,true);
print_r($json_array);
Code: Select all
Array (
[countries] => Array (
[country] => Array (
[0] => Array (
[@attributes] => Array (
[Name] => Germany
[Lat] => 52.6847077739394
[Lng] => -6.81976318359375
[ZoomLevel] => 7 )
)
[1] => Array ( [@attributes] => Array (
[Name] => Sweeden
[Lat] => 54.00131186464818
[Lng] => -7.36358642578125
[ZoomLevel] => 8 )
)
)
)
)
Can anyone please help me on how to do this correctly as I've tried lots of code with multi-dimensional arrays but I've had no luck. I am not able to acces the variable correctly.
Thanks in advance.