我有以下的JSON數組:PHP:我如何從JSON數組中獲取屬性?
<?php
$json = {
"status": "OK",
"results": [ {
"types": [ "street_address" ],
"formatted_address": "5721 N Northcott Ave, Chicago, IL 60631, USA",
"address_components": [ {
"long_name": "5721",
"short_name": "5721",
"types": [ "street_number" ]
}, {
"long_name": "Illinois",
"short_name": "IL",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "60631",
"short_name": "60631",
"types": [ "postal_code" ]
} ],
"geometry": {
"location": {
"lat": 41.9858860,
"lng": -87.7907460
},
"location_type": "ROOFTOP",
"viewport": {
"southwest": {
"lat": 41.9827384,
"lng": -87.7938936
},
"northeast": {
"lat": 41.9890336,
"lng": -87.7875984
}
}
}
} ]
};
?>
使用PHP,我如何才能從上面我的JSON數組的geometery->location->lat
& lng
值?
例如(僞代碼):
<?php
$lat = $json['geometry']['location']['lat']; // 41.9858860
$lng = $json['geometry']['location']['lng']; // -87.7907460
?>
如果我使用json_decode,然後呢?我如何參考LAT和LNG值? – TeddyR 2010-07-08 00:17:49
我已經閱讀過這個鏈接中的例子,但仍然無法弄清楚。這就是爲什麼我現在發佈這個問題到現在 – TeddyR 2010-07-08 00:21:47