php - Remove quotes from Json output -


i need remove double quotes in json output, exlain more. obtain result:

[{"id":"1","nom":"magasin jardins 2","ville":"paris","latlng":["36.85715,10.127245"]} 

i need remove quotes @ value of latlng want obtain latlng":

[36.85715,10.127245] 

this code

  $qry = "select *from magasin";     $result = mysql_query($qry);    //  $promotions = array();     $response = array();     while($row = mysql_fetch_assoc($result)) {     // $promotions[]= $row;  $magasin = array();         $magasin["id"] = $row["id"];         $magasin["nom"] = $row["nom"];         $magasin["ville"] = $row["ville"];         $lat = $row[latitude];         $long = $row[longitude];         $magasin["latlng"][] =floatval($lat).",".floatval($long);;  // push single product final response array         array_push($response, $magasin);     }      mysql_close($con);      echo json_encode($response);  

instead of

$magasin["latlng"][] = floatval($lat).",".floatval($long); 

use

$magasin["latlng"] = array(floatval($lat), floatval($long)); 

if on php 5.4+ can instead use

    $magasin["latlng"] = [floatval($lat), floatval($long)]; 

this allow lat , long values passed floats in array, instead of typecasting string using .",". concatenate.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -