0
我向Google的反向GeoCode系統發出請求,它們返回一個很大的JSON對象,我似乎無法訪問這些屬性。響應看起來是這樣的:訪問stdClass的屬性PHP
{
"results" : [
"address_components" : [
{
"long_name" : "123",
"short_name" : "123",
"types" : [ "street_number" ]
},
{
etc.
}
],
"formatted_address" : "123 Broadway, New York City, NY 10002, USA"
]
}
當它被解碼,它看起來像這樣:
stdClass Object (
[results] => Array (
[0] => stdClass Object (
[address_components] => Array (
[0] => stdClass Object (
[long_name] => 123
[short_name] => 123
[types] => Array ([0] => street_number)
)
)
)
[formatted_address] => 123 Broadway, New York City, NY 10002, USA
)
)
如何去訪問[的formatted_address]屬性?我試過$geoCode->["results"]->formatted_address
但是沒有返回任何值。我很難過,謝謝!
噓,如果你傳遞一個'真'作爲第二個參數'json_decode',你會得到一個多維數組,而不是一組嵌套stdClasses的。嵌套數組更容易處理。 – Charles