JSON对象解析PHP
我不知道如何在PHP中解析JSON对象 我从Google API中获得了此对象(我已删除了我的地址详细信息!): 我想得到我留下的最后一个纬度和经度,JSON对象解析PHP,php,json,Php,Json,我不知道如何在PHP中解析JSON对象 我从Google API中获得了此对象(我已删除了我的地址详细信息!): 我想得到我留下的最后一个纬度和经度,[lat]=>1.234567[lng]=>1.234567 我已经找到了通过这样做获得距离的方法: $directions = json_decode($return); $distance = $directions->routes[0]->legs[0]->distance->text; 然而,获得经度和纬度让我感到
[lat]=>1.234567[lng]=>1.234567
我已经找到了通过这样做获得距离的方法:
$directions = json_decode($return);
$distance = $directions->routes[0]->legs[0]->distance->text;
然而,获得经度和纬度让我感到困惑
如果你能解释一下JSONs,那就更谢谢你了 尝试以下操作:
//northeast
$lat = $directions->routes[0]->bounds->northeast->lat;
$lng = $directions->routes[0]->bounds->northeast->lng;
及
请尝试以下操作:
//northeast
$lat = $directions->routes[0]->bounds->northeast->lat;
$lng = $directions->routes[0]->bounds->northeast->lng;
及
例如,将JSON粘贴到中。只需添加true作为第二个参数,即可将其粘贴到数组中。例如:
json\u decode($MY\u json\u STRING,true)那是一个很棒的网站!帮助我理解JSONObject及其工作原理。对于将来要获得末端坐标的任何人,请使用$array->routes[0]->legs[0]->end_location->lat;例如,将JSON粘贴到中。只需添加true作为第二个参数,即可将其粘贴到数组中。例如:json\u decode($MY\u json\u STRING,true)那是一个很棒的网站!帮助我理解JSONObject及其工作原理。对于将来要获得末端坐标的任何人,请使用$array->routes[0]->legs[0]->end_location->lat;
////southwest
$lat = $directions->routes[0]->bounds->southwest->lat;
$lng = $directions->routes[0]->bounds->southwest->lng;