我正在從事cordova
的工作。從php
腳本我已經生成了一個json
數據。下面是我的JSON數據如何從json數據中刪除雙重qoutes
"11111111": [
{ "x": "2016-01-25 12:58:52", "y": "25.22" },
{ "x": "2016-01-26 13:33:23", "y": "30.14" },
{ "x": "2016-01-27 13:49:18", "y": "35.58" },
{ "x": "2016-01-29 13:55:01", "y": "40.25" },
{ "x": "2016-01-30 14:00:15", "y": "47.25" },
{ "x": "2016-01-31 15:50:15", "y": "14.25" },
{ "x": "2016-02-01 16:16:15", "y": "20.25" },
{ "x": "2016-02-02 17:49:15", "y": "5.25" },
{ "x": "2016-02-03 18:20:15", "y": "77.25" },
{ "x": "2016-02-04 19:30:15", "y": "65.25" }
],
但我想刪除從y
數據double quotes
即
"11111111": [
{ "x": "2016-01-25 12:58:52", "y": 25.22 },
{ "x": "2016-01-26 13:33:23", "y": 30.14 },
{ "x": "2016-01-27 13:49:18", "y": 35.58 },
{ "x": "2016-01-29 13:55:01", "y": 40.25 },
{ "x": "2016-01-30 14:00:15", "y": 47.25 },
{ "x": "2016-01-31 15:50:15", "y": 14.25 },
{ "x": "2016-02-01 16:16:15", "y": 20.25 },
{ "x": "2016-02-02 17:49:15", "y": 5.25 },
{ "x": "2016-02-03 18:20:15", "y": 77.25 },
{ "x": "2016-02-04 19:30:15", "y": 65.25 }
],
更新的代碼:
下面是我的腳本,我已經生成的JSON
if($result)
{
while($row = mysqli_fetch_array($result))
{
$serial = $row['Device_Serial_Number'];
$x = $row['Data_Datetime'];
$y = $row['Energy_kwh'];
if(!isset($data[$serial]))
{
$data[$serial] = [];
}
$data[$serial][] = ['x' => $x , 'y' => $y];
}
mysqli_free_result($result);
}
$json = json_encode($data, JSON_PRETTY_PRINT);
echo "var jsonData = " . $json;
我搜索了許多文章,但無法找到什麼好的解決辦法
任何幫助將高度讚賞
你應該看看'$ y'的創建地點。它目前是PHP中的一個字符串,所以最好的方法是在創建時更改它。目前,您不會共享與創建'$ x'和'$ y'相關的代碼。 – Sirko
如果你從數據庫中得到一個字符串,一個快速修復將會是float:''y'=>(float)$ y' – jeroen
@Sirko請參閱更新 – faisal1208