刪除json輸出的雙引號:[{"id":"1","nom":"Magasin Jardins 2","ville":"Paris","latlng":["36.85715,10.127245"]}
latlng值:[36.85715,10.127245]
代碼:
$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 into final response array
array_push($response, $magasin);
}
mysql_close($con);
echo json_encode($response);
[
{
"id": "1",
"nom": "Magasin Jardins 2",
"ville": "Paris",
"latlng": [
"36.85715,10.127245"
]
}
]
可以看出latlng是一個JSONArray,一個"36.85715,10.127245"是一個字符串