如何从json中删除双引号

时间:2022-06-01 13:02:18

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']);
}

#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']);
}