【发布时间】:2015-06-25 19:00:30
【问题描述】:
我有一个正在运行查询的 MySql 表
<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("GPS") or die(mysql_error());
// Get all the data from the "example" table
$myquery = "SELECT * FROM GPSCoords";
$query = mysql_query($myquery) or die(mysql_error());
$data = array();
for ($x =0; $x < mysql_num_rows($query); $x++){
$data[] = mysql_fetch_assoc($query);
}
echo json_encode($data);
?>
返回的json是这样的:
[
{
"Row": "01SS",
"Number": "1E",
"Latitude": "33.39064308000000",
"Longitude": "-121.918467900",
"LatLong": "[33.39064308000000,-121.918467900]"
}
]
如何将 LatLong 值设为不带引号的值?
即
[
{
"Row": "01SS",
"Number": "1E",
"Latitude": "33.39064308000000",
"Longitude": "-121.918467900",
"LatLong": [
33.39064308000000,
-121.918467900
]
}
]
【问题讨论】:
-
首先你要阅读手册
-
如果可以的话,你应该stop using
mysql_*functions。它们不再被维护并且是officially deprecated。改为了解 prepared statements,并考虑使用 PDO,it's really not hard。