1 回答

TA貢獻1859條經驗 獲得超6個贊
Google Place API 響應看起來像,
"geometry" : {
"location" : {
"lat" : -33.866651,
"lng" : 151.195827
},
"viewport" : {
"northeast" : {
"lat" : -33.8653881697085,
"lng" : 151.1969739802915
},
"southwest" : {
"lat" : -33.86808613029149,
"lng" : 151.1942760197085
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7",
所以你需要將 id 字段聲明為字符串,而不是結構。您需要更改 placeResult 結構。
type modifiedPlaceResult struct {
Geometry struct {
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
} `json:"geometry"`
Id string `json:"id"`
}
嘗試使用modifiedPlaceResult結構來解組數據,一切都會好的。我附上了 Go Playground 的示例:https ://play.golang.org/p/Q4rM-jluoFe
- 1 回答
- 0 關注
- 196 瀏覽
添加回答
舉報