json_encode/json_decode-在PHP中返回stdClass而不是Array [英] json_encode/json_decode - returns stdClass instead of Array in PHP

查看:140
本文介绍了json_encode/json_decode-在PHP中返回stdClass而不是Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

观察这个小脚本:

$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对象变成一个类?

Why does PHP turn the JSON Object into a class?

不是json_encoded的数组,然后json_decoded会产生完全相同的结果吗?

Shouldn't an array that is json_encoded then json_decoded yield the EXACT same result?

推荐答案

Take a closer look at the second parameter of json_decode($json, $assoc, $depth) at https://secure.php.net/json_decode

这篇关于json_encode/json_decode-在PHP中返回stdClass而不是Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆