[请益] 关于json格式问题

楼主: tas72732002 (葱头)   2014-04-17 20:17:49
请问各位大大
我有两个json格式的object
{"a":"a","b":"b","c":"c"}
{"d":"d","e":"e","f":"f"}
我想把他变成 [{"a":"a","b":"b","c":"c"},{"d":"d","e":"e","f":"f"}]
我的做法是
$res[]='{"a":"a","b":"b","c":"c"}';
$res[]='{"d":"d","e":"e","f":"f"}';
$jsonResult=json_encode($res);
结果是 :
["{\"a\":\"a\",\"b\":\"b\",\"c\":\"c\"},{\"d\":\"d\",\"e\":\"e\",\"f\":\"f\"}"]
但我要的结果应该是 :
[{\"a\":\"a\",\"b\":\"b\",\"c\":\"c\"},{\"d\":\"d\",\"e\":\"e\",\"f\":\"f\"}]
请问要如何修改?
作者: mmis1000 (秋月恋枫)   2014-04-17 20:35:00
先decode成物件再放进array如果你要的结果是上面那条的话
作者: yukang (发不完的gmail)   2014-04-18 13:08:00
我以为只要 '['.implode(',',$res).']' XD
作者: up9cloud (九天)   2014-04-18 14:31:00
推yukang解法,XD~
作者: j87b0003 (I'm 邱老虎)   2014-04-19 01:22:00
yukang解法超有趣XD
作者: danny8376 (钓到一只猴子@_@)   2014-04-20 23:58:00
不可否认这解法XD

Links booklink

Contact Us: admin [ a t ] ucptt.com