[請益] 關於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