I try to add a row of mysql query into JSON whit php. I use this code:
public function lugaresCercanos($lng, $lat, $distance){
$result=mysql_query(\"SELECT n
The \ is to escape the quotes (") that are part of the response.
Use stripslashes()
to strip these out.
When a string wrapped in quotes contains quotes, they have to be escaped. The escape character in php is \
.
Try
json_encode($arr, JSON_UNESCAPED_SLASHES);
or
echo str_replace('\/','/',json_encode($mydatas));
(if unescape doesn't work) http://php.net/manual/en/function.json-encode.php
Stop double-encoding your data. Put everything together in one large structure and then encode only that.
Thanks, I resolve it.
$info=array();
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
array_push($info,$row);
}
$info;
$result_final->lugares_cercanos = $info;
Print this:
{"logstatus":"1","lugares_cercanos":[{"nombre":"Rio Amazonas","distancia":"5119.000"}{"nombre":"Swissotel Quito","distancia":"5823.000"}{"nombre":"Laguna de Yaguarcocha","distancia":"71797.000"}]}
If anyone wants to remove the backslashes and also pretty print the JSON data, the following can be used:
json_encode($my_array, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);