简体   繁体   English

如何从json中删除双引号

[英]how to remove double quotes from json

Im trying to plot a graph using jqplot. 我正在尝试使用jqplot绘制图形。 First I load data from mysql and store it in an array. 首先,我从mysql加载数据并将其存储在数组中。

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

Then I json_encode it. 然后我对它进行json_encode Finally I place it on the the jqplot script. 最后,我将其放置在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. 但是jqplot不会读取用双引号引起来的数字值。 The format must be like this: 格式必须是这样的:

[["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. 我到处都看过了,似乎找不到正确的答案,请帮忙。

It looks like the data for 'value' is stored in MySQL as a string. 看起来“值”的数据以字符串形式存储在MySQL中。 You need to convert it back to an integer. 您需要将其转换回整数。 Also, remove the comma before the last end bracket for the array. 另外,删除数组最后一个括号之前的逗号。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM