我在php中有这个json数组代码
$url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-6.893238,107.604273&radius=100&type=point_of_interest&keyword=oleh-oleh&key=mykey";
$data = file_get_contents($url);
$json = json_decode($data);
$i = 0;
$results = array_map(function($result) use (&$i) {
return array ("id" => ++$i , "longitude" => $result->geometry->location->lng, "latitude" => $result->geometry->location->lat, "description" => $result->vicinity, "name" => $result->name);
}, $json->results);
$results = explode('","', $results);
echo json_encode($results);
?>
这会给我一些像这样的数组值:
[{"id":18,"longitude":107.6123014,"latitude":-6.897495399999999,"name":"Kaos Oleh Oleh Khas Bandung & Kaos Otomotif"}]
如何在经度和纬度上添加双引号,像这样:
[{"id":18,"longitude":"107.6123014","latitude":"-6.897495399999999","name":"Kaos Oleh Oleh Khas Bandung & Kaos Otomotif"}]
我尝试使用此代码爆炸:
$results = explode('","', $results);
但是它给了我一个警告:warning explode() expects parameter 2
提前感谢您的帮助。