mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
* Document new json_last_error() function
* Document new JSON error constants git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@271591 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
64658e30c4
commit
4fb8b8c34c
3 changed files with 198 additions and 3 deletions
|
@ -1,9 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
|
||||
<appendix xml:id="json.constants" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
&reftitle.constants;
|
||||
&no.constants;
|
||||
&extension.constants;
|
||||
<para>
|
||||
The following constants indicates an error type returned
|
||||
by <function>json_last_error</function> and are all available
|
||||
as of PHP 5.3.0.
|
||||
</para>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_ERROR_NONE</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
No error have occured.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_ERROR_DEPTH</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
The maximum stack depth have been exceeded.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_ERROR_CTRL_CHAR</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Control character error, possibly wrongly encoded.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_ERROR_SYNTAX</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Syntax error.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</appendix>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
|
143
reference/json/functions/json-last-error.xml
Normal file
143
reference/json/functions/json-last-error.xml
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<refentry xml:id="function.json-last-error" xmlns="http://docbook.org/ns/docbook">
|
||||
<refnamediv>
|
||||
<refname>json_last_error</refname>
|
||||
<refpurpose>Returns the last error occured</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<type>int</type><methodname>json_last_error</methodname>
|
||||
<void />
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
Returns the last error (if any) occured by last JSON parsing.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns an integer, the value can be one of the following:
|
||||
</para>
|
||||
<table>
|
||||
<title>JSON error codes</title>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Constant</entry>
|
||||
<entry>Meaning</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry><constant>JSON_ERROR_NONE</constant></entry>
|
||||
<entry>No error have occured</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>JSON_ERROR_DEPTH</constant></entry>
|
||||
<entry>The maximum stack depth have been exceeded</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>JSON_ERROR_CTRL_CHAR</constant></entry>
|
||||
<entry>Control character error, possibly wrongly encoded</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>JSON_ERROR_SYNTAX</constant></entry>
|
||||
<entry>Syntax error</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title>A <function>json_encode</function> example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// A valid json string
|
||||
$json[] = '{"Organization": "PHP Documentation Team"}';
|
||||
|
||||
// An invalid json string which will cause an syntax
|
||||
// error, in this cause we used ' instead of " for quotation
|
||||
$json[] = "{'Organization': 'PHP Documentation Team'}";
|
||||
|
||||
|
||||
foreach($json as $string)
|
||||
{
|
||||
echo 'Decoding: ' . $string;
|
||||
json_decode($string);
|
||||
|
||||
switch(json_last_error())
|
||||
{
|
||||
case JSON_ERROR_DEPTH:
|
||||
echo ' - Maximum stack depth exceeded';
|
||||
break;
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
echo ' - Unxpected control character found';
|
||||
break;
|
||||
case JSON_ERROR_SYNTAX:
|
||||
echo ' - Syntax error, malformed JSON';
|
||||
break;
|
||||
case JSON_ERROR_NONE:
|
||||
echo ' - No errors';
|
||||
break;
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Decoding: {"Organization": "PHP Documentation Team"} - No errors
|
||||
Decoding: {'Organization': 'PHP Documentation Team'} - Syntax error, malformed JSON
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<para>
|
||||
<simplelist>
|
||||
<member><function>json_decode</function></member>
|
||||
</simplelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
indent-tabs-mode:nil
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"../../../../manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
|
@ -1,11 +1,12 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!--
|
||||
Do NOT translate this file
|
||||
-->
|
||||
<versions>
|
||||
<function name='json_decode' from='PHP 5 >= 5.2.0, PECL json >= 1.2.0'/>
|
||||
<function name='json_encode' from='PHP 5 >= 5.2.0, PECL json >= 1.2.0'/>
|
||||
<function name='json_last_error' from='PHP 5 >= 5.3.0, PECL json >= 1.2.2'/>
|
||||
</versions>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
|
Loading…
Reference in a new issue