我試圖解析來自Google API的響應。解析來自Google地理編碼的json響應
我想知道是否有一種簡單/有效的方法來解析這個數組在php中從'address_components'數組中獲取數據。
{
"results" : [
{
"address_components" : [
{
"long_name" : "10",
"short_name" : "10",
"types" : [ "street_number" ]
},
{
"long_name" : "Downing Street",
"short_name" : "Downing St",
"types" : [ "route" ]
},
{
"long_name" : "Westminster",
"short_name" : "Westminster",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "London",
"short_name" : "London",
"types" : [ "postal_town" ]
},
{
"long_name" : "Greater London",
"short_name" : "Greater London",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "England",
"short_name" : "England",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United Kingdom",
"short_name" : "GB",
"types" : [ "country", "political" ]
},
{
"long_name" : "SW1A 2AA",
"short_name" : "SW1A 2AA",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "10 Downing St, Westminster, London SW1A 2AA, UK",
"geometry" : {
"location" : {
"lat" : 51.5033635,
"lng" : -0.1276248
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 51.5047124802915,
"lng" : -0.126275819708498
},
"southwest" : {
"lat" : 51.5020145197085,
"lng" : -0.128973780291502
}
}
},
"place_id" : "ChIJRxzRQcUEdkgRGVaKyzmkgvg",
"types" : [ "establishment", "point_of_interest" ]
}
],
"status" : "OK"
}
我最初的方法是爲運行通過陣列一個循環,並創建一個新的陣列和鍵設置爲「類型」,但我遇到了一些問題,其中有多個選項的「類型」
什麼是你想要的輸出? – RamRaider
@RamRaider我的目標是用**「address_components」**數組獲得一個數組,其中**「types」**是關鍵字,而**「long_name」**是數值。 – Callum
JavaScript不支持具有鍵名稱的數組 - – RamRaider