开发者社区 问答 正文

删除Json输出的引号

删除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); 

展开
收起
小旋风柴进 2016-03-05 16:16:17 2267 分享 版权
1 条回答
写回答
取消 提交回答
  • [
      {
        "id": "1",
        "nom": "Magasin Jardins 2",
        "ville": "Paris",
        "latlng": [
          "36.85715,10.127245"
        ]
      }
    ]

    可以看出latlng是一个JSONArray,一个"36.85715,10.127245"是一个字符串

    2019-07-17 18:53:41
    赞同 展开评论