json_encode()自动将数组转换为对象

Vir*_*ral 6 php json

当我用json_encode()in 编码一个数组时PHP,所有这些都在这里完成,但是当我用json_decode()它解码时,它给了我stdClassObject而不是Array.这是我的代码:

echo $json=json_encode(array('a'=>1,'b'=>2));
echo '<br>';
print_r(json_decode($json));

// and the result of PHP script is :
{"a":1,"b":2}
// stdClass Object ( [a] => 1 [b] => 2 )
Run Code Online (Sandbox Code Playgroud)

什么将它从数组转换为对象?

我可以将json编码的字符串传递给url以获取另一个页面上的数据,或者是否存在可以执行某些url编码的任何函数?

Anr*_*rgh 9

json_decode()需要一个额外的参数来解码到一个数组.

json_decode($json, true)