这是我的代码:
echo '<br/>';
echo 'Json data from DB '.json_encode($output);
$data=array();
$array=json_decode($output,true);
echo '<br/>';
echo 'Concerted into an array '.json_encode($array);
这是输出:
Json data from DB [{"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","3":"1","key-4":"1"}]
Concerted into an array null
为什么 json_devode 返回 null?如果我尝试这样:
$data = '[{"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","3":"1","key-4":"1"}]';
// convert to an array
$data = json_decode($data, true);
然后正常打印出来:
Json data from DB [{"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","3":"1","key-4":"1"}]
Concerted into an array {"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","4":"1","key-4":"1"}