我正在向Google的反向GeoCode系统发出请求,他们返回一个大型JSON对象,我似乎无法访问这些属性。响应看起来像这样:
{
"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
,但没有返回值。我很难过,谢谢!
答案 0 :(得分:1)
尝试
$geoCode->results[0]->formatted_address