我有这样的数组
datasets:[{"label":"admin ",
"backgroundColor":"#FF6384",
"data":"[0,0,3,30,53,6,0,0,54,0,0,6]"},
{"label":"user1",
"backgroundColor":"#FF6384",
"data":"[0,20,0,3,0,0,5,20,30,0,5,0]"}],
我想从数据数组中删除双引号
我想更改为
datasets:[{"label":"admin ",
"backgroundColor":"#FF6384",
"data":[0,0,3,30,53,6,0,0,54,0,0,6]},
{"label":"user1",
"backgroundColor":"#FF6384",
"data":[0,20,0,3,0,0,5,20,30,0,5,0]}],
答案 0 :(得分:1)
也使用RegEx,但仅在data
键上进行编辑:
// Assuming your data string as $json
$json = preg_replace('/"data":"(\[[0-9,]*\])"/', '"data":$1', $json);
// Output to verify
echo '<pre>' . print_r(json_decode($json, true), true) . '</pre>';
答案 1 :(得分:0)
不太优雅,但在功能上
preg_replace("/\"(\[.*\])\"/", "$1", $Json);
$1
是包含[something]的字符串。