在php中格式化json数据

时间:2014-11-14 11:03:47

标签: php json

我有以下格式的json数据

["0","0","0","0","0","0","0","2","5","4","3","0"]

我想使用php

将上述数据转换为以下格式
[0,0,0,0,0,0,0,2,5,4,3,0]

我如何使用php

执行此操作

由于

2 个答案:

答案 0 :(得分:2)

您可以使用array_map将数组中的所有项类型转换为带回调intval的整数。

对于数组中的整数:

$array = array_map('intval', json_decode('["0","0","0","0","0","0","0","2","5","4","3","0"]'));

从数组中检索JSON:

echo json_encode($array);

答案 1 :(得分:0)

$string = '["0","0","0","0","0","0","0","2","5","4","3","0"]';
echo str_replace('"','', $string);

输出是:

[0,0,0,0,0,0,0,2,5,4,3,0]