これが私のコードです:
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"}