json_encode 的第二個參數詳解

預約義常量

下列常量由此擴展定義,且僅在此擴展編譯入 PHP 或在運行時動態載入時可用。php

如下常量表示了 json_last_error() 所返回的錯誤類型。json

  • JSON_ERROR_NONE (integer)數組

  • 沒有錯誤發生。自 PHP 5.3.0 起生效。編碼

  • JSON_ERROR_DEPTH (integer)spa

  • 到達了最大堆棧深度。自 PHP 5.3.0 起生效。.net

  • JSON_ERROR_STATE_MISMATCH (integer)code

  • 出現了下溢(underflow)或者模式不匹配。自 PHP 5.3.0 起生效。orm

  • JSON_ERROR_CTRL_CHAR (integer)字符串

  • 控制字符錯誤,多是編碼不對。自 PHP 5.3.0 起生效。get

  • JSON_ERROR_SYNTAX (integer)

  • 語法錯誤。 自 PHP 5.3.0 起生效。

  • JSON_ERROR_UTF8 (integer)

  • 異常的 UTF-8 字符,也許是由於不正確的編碼。 此常量自 PHP 5.3.1 起生效。

下面的常量能夠和 json_encode() 的 form 選項結合使用。

  • JSON_HEX_TAG (integer)

  • 全部的 < 和 > 轉換成 \u003C 和 \u003E。 自 PHP 5.3.0 起生效。

  • JSON_HEX_AMP (integer)

  • 全部的 & 轉換成 \u0026。 自 PHP 5.3.0 起生效。

  • JSON_HEX_APOS (integer)

  • 全部的 ' 轉換成 \u0027。 自 PHP 5.3.0 起生效。

  • JSON_HEX_QUOT (integer)

  • 全部的 " 轉換成 \u0022。 自 PHP 5.3.0 起生效。

  • JSON_FORCE_OBJECT (integer)

  • 使一個非關聯數組輸出一個類(Object)而非數組。 在數組爲空而接受者須要一個類(Object)的時候尤爲有用。 自 PHP 5.3.0 起生效。

  • JSON_NUMERIC_CHECK (integer)

  • 將全部數字字符串編碼成數字(numbers)。 自 PHP 5.3.3 起生效。

  • JSON_BIGINT_AS_STRING (integer)

  • 將大數字編碼成原始字符原來的值。 自 PHP 5.4.0 起生效。

  • JSON_PRETTY_PRINT (integer)

  • 用空白字符格式化返回的數據。 自 PHP 5.4.0 起生效。

  • JSON_UNESCAPED_SLASHES (integer)

  • 不要編碼 /。 自 PHP 5.4.0 起生效。

  • JSON_UNESCAPED_UNICODE (integer)

  • 以字面編碼多字節 Unicode 字符(默認是編碼成 \uXXXX)。 自 PHP 5.4.0 起生效。

相關文章
相關標籤/搜索