我有一个来自 Google geo api 的数组,这个结果来自 json,所以我使用 json_decode()。
stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => 78213
[short_name] => 78213
[types] => Array
(
[0] => postal_code
)
)
[1] => stdClass Object
(
[long_name] => San Antonio
[short_name] => San Antonio
[types] => Array
(
[0] => locality
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Bexar
[short_name] => Bexar
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
但是,当我尝试访问$result->0->address_components
时,我会收到此错误
解析错误:解析错误,在 C:\wamp\www\test.php 中需要 'T_STRING' 或 'T_VARIABLE' 或 "{" 或 "$"。
如何访问 0 索引值?