【问题标题】:read array after decoding from json Google Maps从 json Google Maps 解码后读取数组
【发布时间】:2013-03-15 19:21:45
【问题描述】:

我有一个问题,我不明白如何获取'array 的address_components 字段long_name 示例,编写此脚本:

$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$lat.','.$lng.'&sensor=true';
$data = @file_get_contents($url);
$jsondata = json_decode($data , true);

if(is_array($jsondata ))
{
      $long_name= $jsondata ['results']['address_components'][0]['long_name'];
}

看一个建议

谢谢

【问题讨论】:

    标签: php arrays json api maps


    【解决方案1】:

    $results 是一个数组。如果你想得到第一个结果:

    $jsondata ['results'][0]['address_components'][0]['long_name']
    

    【讨论】:

      猜你喜欢
      • 2012-04-15
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 2019-11-11
      相关资源
      最近更新 更多