浏览模式: 普通 | 列表
1月, 2013 | 1

json Cannot use object of type stdClass as array

[ 2013-01-26 16:16:03 | 作者: admin ]
json_decode(Cannot use object of type stdClass as array)

最近用 php 的 array 處理下述的程式碼,

$author = 'Mary';
$test[$author] = array('message'=>'測試', 'time'=> 1237175074);
$test2 = json_decode(json_encode($test));
print_r($test2[$author]);

一直得到下述的錯誤訊息

Cannot use object of type stdClass as array

這個程式碼,只要第三行加個 true,就可以了。

$author = 'Mary';
$test[$author] = array('message'=>'測試', 'time'=> 1237175074);
...

阅读全文…
1