如何格式化json_encode的结果

时间:2014-11-14 10:44:13

标签: php arrays json

首先我用json_ncode得到这个结果:

[{"name":"Pendapatan","y":"1464333560100.00"},{"name":"realpen","y":"500831727342.91"},{"name":"Belanja","y":"1074625188660.00"},{"name":"realbel","y":"239521231607.23"},{"name":"Pembiayaan","y":"52029536970.00"},{"name":"realpem","y":"1809194488.25"}]

当我使用str_replace时('"','',$ result);数据变成这样:

[{name:Pendapatan,y:1464333560100.00},{name:realpen,y:500831727342.91},{name:Belanja,y:1074625188660.00},{name:realbel,y:239521231607.23},{name:Pembiayaan,y:52029536970.00},{name:realpem,y:1809194488.25}]

我应该使用什么格式删除" []",只留下{a:val,b:val .... etc}

1 个答案:

答案 0 :(得分:1)

最简单的解决方案:

substr($yourJson, 1, -1);

虽然如果你应该以这种方式这样做是有争议的,正如评论中的一些用户已经说过。