php怎么将数组数组转化为json格式的数据
例如
Array
(
[0] => a
[1] => b
[2] => c
[3] => h
[4] => f
)
我直接使用json_encode($a); //$a就是上面使用print_r()打印出的结果
结果显示为["a","b","c","h","f"],而事实上我想要的是{"0":"a","1":"b","2":"c","3":"h","4":"f"},只有这种格式我在ios接收到的数据才不为空
------解决方案--------------------
那就自己拼装啰
$a = array('a', 'b', 'c', 'd');<br />foreach($a as $k=>$v) $b[] = sprintf('"%s":"%s"', $k, $v);<br />echo '{' . join(',', $b) . '}';