我有一个来自JSON的多维数组。我似乎无法从所有人打印一个值。它要么没有给我任何东西,要么说array
。我需要打印所有zip_code
字段。
$spit = json_decode($result);
收率:
stdClass Object
(
[zip_codes] => Array
(
[0] => stdClass Object
(
[zip_code] => 33779
[distance] => 9.513
[city] => Largo
[state] => FL
)
[1] => stdClass Object
(
[zip_code] => 33771
[distance] => 9.188
[city] => Largo
[state] => FL
)
[2] => stdClass Object
(
[zip_code] => 33760
[distance] => 9.989
[city] => Clearwater
[state] => FL
)
[3] => stdClass Object
(
[zip_code] => 33770
[distance] => 8.525
[city] => Largo
[state] => FL
)
[4] => stdClass Object
(
[zip_code] => 33786
[distance] => 8.153
[city] => Belleair Beach
[state] => FL
)
[5] => stdClass Object
(
[zip_code] => 33764
[distance] => 7.651
[city] => Clearwater
[state] => FL
)
[6] => stdClass Object
(
[zip_code] => 33756
[distance] => 6.373
[city] => Clearwater
[state] => FL
)
我尝试使用$zip=$spit->zip_codes->zip_code;
和$zip=['zip_codes']['zip_code'];
我确信我只是错过了显而易见的事情,但已经尝试了大约20种方法来回应它而没有运气。
答案 0 :(得分:0)
更改
$spit = json_decode($result);
到
$spit = json_decode($result,1);
这会将JSON转换为数组,然后您可以将邮政编码打印为
print_r($spit["zip_codes"]);