因爲我更喜歡更面向對象的方法,所以我編寫了自己的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