在url上使用json_decode后如何获取数组项的值?

问题描述 投票:0回答:2

这是我的代码...

$resp = json_decode($resp_json, true); 返回数组($resp[0]['lat'], $resp[0]['lon']);

这是我的 var_dump(json_decode($resp_json, true)); // vardump 在下面

///

array(1) { [0]=> array(15) { ["place_id"]=> int(308959017) ["licence"]=> string(70) "数据 © OpenStreetMap 贡献者,ODbL 1.0。 http: //osm.org/copyright" ["osm_type"]=> string(3) "way" ["osm_id"]=> int(570688234) ["lat"]=> string(10) "34.0722265" [" lon"]=> 字符串(19) "-117.43345301493153" ["class"]=> 字符串(7) "便利设施" ["type"]=> 字符串(8) "医院" ["place_rank"]=> int( 30) ["重要性"]=> 浮动(0.18764122278025944) ["地址类型"]=> 字符串(7) "设施" ["名称"]=> 字符串(40) "凯撒永久丰塔纳医疗中心" ["display_name"] => string(127) "Kaiser Permanente Fontana 医疗中心, 9961, Sierra Avenue, Fontana, San Bernardino County, California, 92335, United States" ["address"]=> array(10) { ["amenity"]=>字符串(40)“凯撒永久丰塔纳医疗中心”[“house_number”]=>字符串(4)“9961”[“道路”]=>字符串(13)“塞拉大道”[“城市”]=>字符串(7 ) “丰塔纳” [“县”]=> 字符串(21) “圣贝纳迪诺县” [“州”]=> 字符串(10) “加利福尼亚州” [“ISO3166-2-lvl4”]=> 字符串(5) “ US-CA" ["postcode"]=> string(5) "92335" ["country"]=> string(13) "United States" ["country_code"]=> string(2) "us" } ["边界框"]=> 数组(4) { [0]=> 字符串(10) "34.0705513" [1]=> 字符串(10) "34.0738878" [2]=> 字符串(12) "-117.4355221" [3] => 字符串(12) "-117.4294710" } } }

///

我没有获得纬度或经度数组值的任何返回值。我在那里看到它,但我无法提取它。请告诉我,我是 json 新手,这是我的第一篇文章。

我尝试了很多不同的方法来输出数组,但仍然一无所获。

php arrays json file-get-contents
2个回答
0
投票

对我来说一切都很顺利。您能给我们多一点代码吗?


0
投票

我发现代码确实有效。我没提取正确。我最终只是将每个数组分配给这样的变量,现在我有了数据。

$don = array($resp[0]['lat']);
$dom = array($resp[0]['lon']);

echo $resp[0]['lat'];
echo $resp[0]['lon'];
© www.soinside.com 2019 - 2024. All rights reserved.