观察这个小脚本:
$array = array('stuff' => 'things'); print_r($array); //prints - Array ( [stuff] => things ) $arrayEncoded = json_encode($array); echo $arrayEncoded . "<br />"; //prints - {"stuff":"things"} $arrayDecoded = json_decode($arrayEncoded); print_r($arrayDecoded); //prints - stdClass Object ( [stuff] => things )
PHP为什么将JSON对象变成一个类?
如果不是一个数组,它是json_encoded那么json_decoded产生完全相同的结果?
json_encoded
json_decoded
采取在的第二个参数仔细看看json_decode($json, $assoc, $depth)在https://secure.php.net/json_decode
json_decode($json, $assoc, $depth)