Files
doc-fr/reference/json/functions/json-last-error.xml
Damien Seguy c6d70d95c6 synch iwth en
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@278185 c90b9560-bf6c-de11-be94-00142212c4b1
2009-04-02 16:17:30 +00:00

149 lines
3.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.2 $ -->
<!-- EN-Revision: 1.5 Maintainer: yannick Status: ready -->
<!-- Reviewed: yes -->
<refentry xml:id="function.json-last-error" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>json_last_error</refname>
<refpurpose>Retourne la dernière erreur JSON</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>json_last_error</methodname>
<void />
</methodsynopsis>
<para>
<function>json_last_error</function> retourne la
dernière erreur, s'il y en a eu, survenue lors
de la dernière analyse JSON.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Retourne une des constantes suivantes :
</para>
<table>
<title>Codes d'erreur JSON</title>
<tgroup cols="2">
<thead>
<row>
<entry>Constante</entry>
<entry>Signification</entry>
</row>
</thead>
<tbody>
<row>
<entry><constant>JSON_ERROR_NONE</constant></entry>
<entry>Aucune erreur n'est survenue</entry>
</row>
<row>
<entry><constant>JSON_ERROR_DEPTH</constant></entry>
<entry>La profondeur maximale de la pile a été atteinte</entry>
</row>
<row>
<entry><constant>JSON_ERROR_CTRL_CHAR</constant></entry>
<entry>Erreur lors du contrôle des caractères ; probablement un encodage incorrect</entry>
</row>
<row>
<entry><constant>JSON_ERROR_SYNTAX</constant></entry>
<entry>Erreur de syntaxe</entry>
</row>
</tbody>
</tgroup>
</table>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Exemple avec <function>json_last_error</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Une chaîne JSON valide
$json[] = '{"Organisation": "Équipe de Documentation PHP"}';
// Une chaîne json invalide qui va générer une erreur de syntaxe,
// ici, utilisation de ' au lieu de "
$json[] = "{'Organisation': 'Équipe de Documentation PHP'}";
foreach($json as $string)
{
echo 'Décodage : ' . $string;
json_decode($string);
switch(json_last_error())
{
case JSON_ERROR_DEPTH:
echo ' - Profondeur maximale atteinte';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Erreur lors du contrôle des caractères';
break;
case JSON_ERROR_SYNTAX:
echo ' - Erreur de syntaxe ; JSON malformé';
break;
case JSON_ERROR_NONE:
echo ' - Aucune erreur';
break;
}
echo PHP_EOL;
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Décodage : {"Organisation": "Équipe de Documentation PHP"} - Aucune erreur
Décodage : {'Organisation': 'Équipe de Documentation PHP'} - Erreur de syntaxe ; JSON malformé
]]>
</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
-->