当我尝试使用静态值对数组进行json编码时,它输出如下:
[
{"data":[0,0,0,0,0,5],"name":"www.google.com"},
{"data":[0,0,0,0,0,4],"name":"www.yahoo.com"},
{"data":[0,0,0,0,85,0],"name":"www.bing.com"}
]
然后我尝试使用动态值进行json编码,就像这样输出
[
{"data":[0,0,0,0,0,"5"],"name":"www.google.com"},
{"data":[0,0,0,0,0,"4"],"name":"www.yahoo.com"},
{"data":[0,0,0,0,"85",0],"name":"www.bing.com"}
]
对于非零值,有一个额外的双引号(“”)如何删除它?
答案 0 :(得分:4)
您需要使用 intval 进行解析,例如:
$arr = array("1", intval("2"));
echo json_encode($arr);
输出:
["1",2]