<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.json.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'json.constants.php',
    1 => '预定义常量',
    2 => '预定义常量',
  ),
  'up' => 
  array (
    0 => 'book.json.php',
    1 => 'JSON',
  ),
  'prev' => 
  array (
    0 => 'json.installation.php',
    1 => '安装',
  ),
  'next' => 
  array (
    0 => 'class.jsonexception.php',
    1 => 'JsonException',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/json/constants.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="json.constants" class="appendix">
 <h1 class="title">预定义常量</h1>

 <p class="simpara">下列常量由此扩展定义，且仅在此扩展编译入 PHP 或在运行时动态载入时可用。</p>
 <p class="para">
  以下常量表示了 <span class="function"><a href="function.json-last-error.php" class="function">json_last_error()</a></span> 函数，或
  <span class="classname"><a href="class.jsonexception.php" class="classname">JsonException</a></span> 类中的
  <var class="varname">code</var> 变量所返回的错误类型。
 </p>
 <dl>
  
   <dt id="constant.json-error-none">
    <strong><code><a href="json.constants.php#constant.json-error-none">JSON_ERROR_NONE</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     没有错误发生。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-depth">
    <strong><code><a href="json.constants.php#constant.json-error-depth">JSON_ERROR_DEPTH</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     到达了最大堆栈深度。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-state-mismatch">
    <strong><code><a href="json.constants.php#constant.json-error-state-mismatch">JSON_ERROR_STATE_MISMATCH</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     出现了下溢（underflow）或者模式不匹配。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-ctrl-char">
    <strong><code><a href="json.constants.php#constant.json-error-ctrl-char">JSON_ERROR_CTRL_CHAR</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     控制字符错误，可能是编码不对。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-syntax">
    <strong><code><a href="json.constants.php#constant.json-error-syntax">JSON_ERROR_SYNTAX</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     语法错误。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-utf8">
    <strong><code><a href="json.constants.php#constant.json-error-utf8">JSON_ERROR_UTF8</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     异常的 UTF-8 字符，也许是因为不正确的编码。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-recursion">
    <strong><code><a href="json.constants.php#constant.json-error-recursion">JSON_ERROR_RECURSION</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
      传递给 <span class="function"><a href="function.json-encode.php" class="function">json_encode()</a></span> 函数的对象或数组包含了递归引用，导致无法被编码。如果打开了
      <strong><code><a href="json.constants.php#constant.json-partial-output-on-error">JSON_PARTIAL_OUTPUT_ON_ERROR</a></code></strong> 选项，则牵涉到递归引用的数据会转换成
      <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> 后返回。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-inf-or-nan">
    <strong><code><a href="json.constants.php#constant.json-error-inf-or-nan">JSON_ERROR_INF_OR_NAN</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     传递给 <span class="function"><a href="function.json-encode.php" class="function">json_encode()</a></span> 函数的参数中包含了
     <a href="language.types.float.php#language.types.float.nan" class="link"><strong><code><a href="math.constants.php#constant.nan">NAN</a></code></strong></a>
     或 <a href="function.is-infinite.php" class="link"><strong><code><a href="math.constants.php#constant.inf">INF</a></code></strong></a>，导致编码出错。如果打开了
     <strong><code><a href="json.constants.php#constant.json-partial-output-on-error">JSON_PARTIAL_OUTPUT_ON_ERROR</a></code></strong> 选项，则牵涉到对应不可编码的数字，会转换成数字
     <code class="literal">0</code> 后返回。
    </span>
   </dd>
  
   
   <dt id="constant.json-error-unsupported-type">
    <strong><code><a href="json.constants.php#constant.json-error-unsupported-type">JSON_ERROR_UNSUPPORTED_TYPE</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
      传递了不支持的数据类型给 <span class="function"><a href="function.json-encode.php" class="function">json_encode()</a></span> 函数，比如 <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>。如果打开了
      <strong><code><a href="json.constants.php#constant.json-partial-output-on-error">JSON_PARTIAL_OUTPUT_ON_ERROR</a></code></strong> 选项，则对于不支持的数据类型，会转换成
      <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> 后返回。
    </span>
   </dd>
  
  
  
   <dt id="constant.json-error-invalid-property-name">
    <strong><code><a href="json.constants.php#constant.json-error-invalid-property-name">JSON_ERROR_INVALID_PROPERTY_NAME</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     当 JSON 对象解码为 PHP 对象时，传递给 <span class="function"><a href="function.json-decode.php" class="function">json_decode()</a></span> 的字符串包含以 \u0000 字符开头的 key。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-utf16">
    <strong><code><a href="json.constants.php#constant.json-error-utf16">JSON_ERROR_UTF16</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     传递给 <span class="function"><a href="function.json-encode.php" class="function">json_encode()</a></span> 的 JSON 字符串包含 Unicode 转义，其中含有单个未配对的 UTF-16 代理字符。
    </span>
   </dd>
  
  
   <dt id="constant.json-error-non-backed-enum">
    <strong><code><a href="json.constants.php#constant.json-error-non-backed-enum">JSON_ERROR_NON_BACKED_ENUM</a></code></strong>
    (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     传递给 <span class="function"><a href="function.json-encode.php" class="function">json_encode()</a></span> 的值包含了无法序列化的非支持的枚举。
     自 PHP 8.1.0 起生效。
    </span>
   </dd>
  
 </dl>

 <p class="para">
  下面的常量可以和 <span class="function"><a href="function.json-decode.php" class="function">json_decode()</a></span> 的 form 选项结合使用。
 </p>
 <dl>
  
   <dt id="constant.json-bigint-as-string">
    <strong><code><a href="json.constants.php#constant.json-bigint-as-string">JSON_BIGINT_AS_STRING</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     将大数字编码成原始字符原来的值。
    </span>
   </dd>
  
  
   <dt id="constant.json-object-as-array">
    <strong><code><a href="json.constants.php#constant.json-object-as-array">JSON_OBJECT_AS_ARRAY</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     将 JSON 对象作为数组解码。当调用 <span class="function"><a href="function.json-decode.php" class="function">json_decode()</a></span> 且第二个参数为
     <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> 时此选项会自动添加。
    </span>
   </dd>
  
 </dl>
 
 <p class="para">
  下面的常量可以和 <span class="function"><a href="function.json-encode.php" class="function">json_encode()</a></span> 的 form 选项结合使用。
  
 </p>
 <dl>
  
   <dt id="constant.json-hex-tag">
    <strong><code><a href="json.constants.php#constant.json-hex-tag">JSON_HEX_TAG</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     所有的 &lt; 和 &gt; 转换成 \u003C 和 \u003E。
    </span>
   </dd>
  
  
   <dt id="constant.json-hex-amp">
    <strong><code><a href="json.constants.php#constant.json-hex-amp">JSON_HEX_AMP</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     所有的 &amp; 转换成 \u0026。
    </span>
   </dd>
  
  
   <dt id="constant.json-hex-apos">
    <strong><code><a href="json.constants.php#constant.json-hex-apos">JSON_HEX_APOS</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     所有的 &#039; 转换成 \u0027。
    </span>
   </dd>
  
  
   <dt id="constant.json-hex-quot">
    <strong><code><a href="json.constants.php#constant.json-hex-quot">JSON_HEX_QUOT</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     所有的 &quot; 转换成 \u0022。
    </span>
   </dd>
  
  
   <dt id="constant.json-force-object">
    <strong><code><a href="json.constants.php#constant.json-force-object">JSON_FORCE_OBJECT</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     使一个非关联数组输出一个类（Object）而非数组。
     在数组为空而接受者需要一个类（Object）的时候尤其有用。
    </span>
   </dd>
  
  
   <dt id="constant.json-numeric-check">
    <strong><code><a href="json.constants.php#constant.json-numeric-check">JSON_NUMERIC_CHECK</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     将所有数字字符串编码成数字（numbers）。
    </span>
   </dd>
  
  
  
   <dt id="constant.json-pretty-print">
    <strong><code><a href="json.constants.php#constant.json-pretty-print">JSON_PRETTY_PRINT</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     用空白字符格式化返回的数据。
    </span>
   </dd>
  
  
   <dt id="constant.json-unescaped-slashes">
    <strong><code><a href="json.constants.php#constant.json-unescaped-slashes">JSON_UNESCAPED_SLASHES</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     不要编码 <code class="literal">/</code>。
    </span>
   </dd>
  
  
   <dt id="constant.json-unescaped-unicode">
    <strong><code><a href="json.constants.php#constant.json-unescaped-unicode">JSON_UNESCAPED_UNICODE</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     以字面编码多字节 Unicode 字符（默认是编码成 \uXXXX）。
    </span>
   </dd>
  
  
   <dt id="constant.json-partial-output-on-error">
    <strong><code><a href="json.constants.php#constant.json-partial-output-on-error">JSON_PARTIAL_OUTPUT_ON_ERROR</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     用不可编码的值来代替失败。
    </span>
   </dd>
  
  
   <dt id="constant.json-preserve-zero-fraction">
    <strong><code><a href="json.constants.php#constant.json-preserve-zero-fraction">JSON_PRESERVE_ZERO_FRACTION</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     确保 <span class="type"><a href="language.types.float.php" class="type float">float</a></span> 值始终编码为为 float 值。
    </span>
   </dd>
  
  
   <dt id="constant.json-unescaped-line-terminators">
    <strong><code><a href="json.constants.php#constant.json-unescaped-line-terminators">JSON_UNESCAPED_LINE_TERMINATORS</a></code></strong>
      (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     The line terminators are kept unescaped when
     <strong><code><a href="json.constants.php#constant.json-unescaped-unicode">JSON_UNESCAPED_UNICODE</a></code></strong> is supplied. It uses the same
     behaviour as it was before PHP 7.1 without this constant.
     Available since PHP 7.1.0.
    </span>
   </dd>
  
 </dl>


 <p class="para">
  下面的常量可以和 <span class="function"><a href="function.json-decode.php" class="function">json_decode()</a></span> 及 <span class="function"><a href="function.json-encode.php" class="function">json_encode()</a></span> 的 form 选项结合使用。
 </p>
 <dl>
  
   <dt id="constant.json-invalid-utf8-ignore">
    <strong><code><a href="json.constants.php#constant.json-invalid-utf8-ignore">JSON_INVALID_UTF8_IGNORE</a></code></strong>
    (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     忽略无效的 UTF-8 字符。自 PHP 7.2.0 起生效。
    </span>
   </dd>
  
  
   <dt id="constant.json-invalid-utf8-substitute">
    <strong><code><a href="json.constants.php#constant.json-invalid-utf8-substitute">JSON_INVALID_UTF8_SUBSTITUTE</a></code></strong>
    (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     将无效 UTF-8 字符转换为 \0xfffd（Unicode 字符“虚缺号”）。自 PHP 7.2.0 起生效。
    </span>
   </dd>
  
  
   <dt id="constant.json-throw-on-error">
    <strong><code><a href="json.constants.php#constant.json-throw-on-error">JSON_THROW_ON_ERROR</a></code></strong>
    (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)
   </dt>
   <dd>
    <span class="simpara">
     如果发生错误则会抛出 <span class="classname"><a href="class.jsonexception.php" class="classname">JsonException</a></span>，而不是通过 <span class="function"><a href="function.json-last-error.php" class="function">json_last_error()</a></span>
     和 <span class="function"><a href="function.json-last-error-msg.php" class="function">json_last_error_msg()</a></span> 检索设置到全局的错误状态。<strong><code><a href="json.constants.php#constant.json-partial-output-on-error">JSON_PARTIAL_OUTPUT_ON_ERROR</a></code></strong>
     优先于 <strong><code><a href="json.constants.php#constant.json-throw-on-error">JSON_THROW_ON_ERROR</a></code></strong>。自 PHP 7.3.0 起生效。
    </span>
   </dd>
  
 </dl>

</div>
<?php manual_footer($setup); ?>