因为我更喜欢更面向对象的方法,所以我编写了自己的json类来处理解码和编码的json_last_error。json_decode自己的类 - 警告:深度必须大于零
不知怎的,我得到了一个PHP警告json_decode方法的深度属性。
PHP的核心API(日食PDT)的json_decode方法如下所示:
function json_decode ($json, $assoc = null, $depth = null) {}
到目前为止好,但如果我写我自己的类这样的:
function my_json_decode ($json, $assoc = null, $depth = null) {
return json_decode($json, $assoc, $depth);
}
和尝试运行它如下:
$json = '{ "sample" : "json" }';
var_dump(my_json_decode($json));
我得到以下警告:
Warning: json_decode(): Depth must be greater than zero in/
我错过了什么吗?我想如果我将一个属性传递给一个将属性本身设置为null的方法,那么它应该没问题?!
使用:服务器:Apache/2.2.22(Unix的)PHP/5.3.10
感谢您的帮助!
[编辑]澄清在我的理解是泄漏:
我使用Eclipse靛蓝+ PDT。 org.eclipse.php.core.language的PDT PHP核心API不同于什么php.net说的json_decode:
json_decode org.eclipse.php.core.language:
json_decode ($json, $assoc = null, $depth = null)
json_decode PHP .NET:
json_decode (string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]])
感谢Gopi解释为什么我的对象深度是2,为什么我不能像PHP核心API那样传递NULL。 assoc NULL也不在核心api中。这个PHP核心API出eclipse PDT困惑了我,因为它也不同于php.net所说的json_decode – Talisin 2012-07-21 08:09:27
@Talisin一定要接受答案并关闭这个问题如果任何答案满足你 – gopi1410 2012-07-21 08:17:02
我会像往常一样让我找到为什么eclipse PHP核心api与php.net不同。 – Talisin 2012-07-21 08:20:15