mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-29 20:32:10 +02:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@277213 c90b9560-bf6c-de11-be94-00142212c4b1
213 lines
4.8 KiB
XML
213 lines
4.8 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.13 $ -->
|
|
<!-- EN-Revision: 1.10 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
|
|
<refentry xml:id="function.json-decode" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>json_decode</refname>
|
|
<refpurpose>Décode une chaîne JSON</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>json_decode</methodname>
|
|
<methodparam><type>string</type><parameter>json</parameter></methodparam>
|
|
<methodparam choice="opt"><type>bool</type><parameter>assoc</parameter><initializer>false</initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>depth</parameter><initializer>512</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Récupère une chaîne encodée JSON et la convertie en une variable PHP.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>json</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La chaîne <parameter>json</parameter> à décoder.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>assoc</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Lorsque ce paramètre vaut &true;, l'objet retourné sera converti en un
|
|
tableau associatif.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>depth</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retourne un &object; ou, si le paramètre optionnel
|
|
<parameter>assoc</parameter> vaut &true;, un tableau associatif.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>json_decode</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
|
|
|
|
var_dump(json_decode($json));
|
|
var_dump(json_decode($json, true));
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
object(stdClass)#1 (5) {
|
|
["a"] => int(1)
|
|
["b"] => int(2)
|
|
["c"] => int(3)
|
|
["d"] => int(4)
|
|
["e"] => int(5)
|
|
}
|
|
|
|
array(5) {
|
|
["a"] => int(1)
|
|
["b"] => int(2)
|
|
["c"] => int(3)
|
|
["d"] => int(4)
|
|
["e"] => int(5)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Autre exemple avec <function>json_decode</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$json = '{"foo-bar": 12345}';
|
|
|
|
$obj = json_decode($json);
|
|
print $obj->{'foo-bar'}; // 12345
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>Erreurs habituelles lors de l'utilisation de la fonction <function>json_decode</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
// Les chaînes suivantes sont valides en JavaScript mais pas en JSON
|
|
|
|
// Le nom et la valeur doivent être entourrés de double-guillemets.
|
|
// Les simple-guillements ne sont pas valides
|
|
$bad_json = "{ 'bar': 'baz' }";
|
|
json_decode($bad_json); // null
|
|
|
|
// le nom doit être entourré de double-guillemets
|
|
$bad_json = '{ bar: "baz" }';
|
|
json_decode($bad_json); // null
|
|
|
|
// la virgule de fin n'est pas autorisée
|
|
$bad_json = '{ bar: "baz", }';
|
|
json_decode($bad_json); // null
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
La spécification JSON ne fait pas partie de Javascript
|
|
mais d'un sous-projet de Javascript.
|
|
</para>
|
|
</note>
|
|
<caution>
|
|
<para>
|
|
Cette fonction retournera &false; si les données encodées JSON sont plus
|
|
profondes que 127 éléments.
|
|
</para>
|
|
</caution>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>5.2.3</entry>
|
|
<entry>La limite a été élevée de 20 à 128</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>json_encode</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
|
|
--> |