如何從json中刪除雙引號

[英]how to remove double quotes from json


Im trying to plot a graph using jqplot. First I load data from mysql and store it in an array.

我試圖用jqplot繪制圖形。首先,我從mysql加載數據並將其存儲在一個數組中。

foreach ($data as $row){
$values[] = array($row['date'],$row['value'],);
}

Then I json_encode it. Finally I place it on the the jqplot script.

然后我json_encode它。最后我把它放在jqplot腳本上。

The problem is that the json_encode outputs this:

問題是json_encode輸出:

[["12\/12\/2014","10"],["12\/13\/2014","20"],["12\/14\/2014","30"],];

But jqplot doesn't read number values wrapped on double quotes. The format must be like this:

但是jqplot不會讀取包含在雙引號上的數字值。格式必須如下:

[["12\/12\/2014",10],["12\/13\/2014",20],["12\/14\/2014",30],];

I've looked everywhere and can't seem to find the right answer, please help.

我到處尋找,似乎無法找到正確的答案,請幫忙。

1 个解决方案

#1


1  

It looks like the data for 'value' is stored in MySQL as a string. You need to convert it back to an integer. Also, remove the comma before the last end bracket for the array.

看起來'value'的數據作為字符串存儲在MySQL中。您需要將其轉換回整數。另外,刪除數組的最后一個結束括號之前的逗號。

foreach ($data as $row){
    values[] = array($row['date'], (int) $row['value']);
}

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/12/18/712f285ffec2fd2e67360d8e8fa43926.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com