1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- EN-Revision: 24249 -->
<!-- Reviewed: no -->
<sect1 id="zend.json.basics">
<title>Utilisation de base</title>
<para>
L'utilisation de <classname>Zend_Json</classname> implique l'emploi des deux méthodes
statiques publiques disponibles : <methodname>Zend_Json::encode()</methodname> et
<methodname>Zend_Json::decode()</methodname>. <programlisting language="php"><![CDATA[
// Obtention d'une valeur
$phpNatif = Zend_Json::decode($valeurCodee);
// Codage pour renvoi au client :
$json = Zend_Json::encode($phpNatif);
]]></programlisting></para>
<sect2 id="zend.json.basics.prettyprint">
<title>Pretty-printing JSON</title>
<para>
Sometimes, it may be hard to explore <acronym>JSON</acronym> data generated by
<methodname>Zend_Json::encode()</methodname>, since it has no spacing or indentation.
In order to make it easier, <classname>Zend_Json</classname>
allows you to pretty-print <acronym>JSON</acronym> data in the human-readable format
with <methodname>Zend_Json::prettyPrint()</methodname>.
</para>
<programlisting language="php"><![CDATA[
// Encode it to return to the client:
$json = Zend_Json::encode($phpNative);
if($debug) {
echo Zend_Json::prettyPrint($json, array("indent" => " "));
}
]]></programlisting>
<para>
Second optional argument of <methodname>Zend_Json::prettyPrint()</methodname> is an
option array. Option <property>indent</property> allows to set indentation string - by
default it's a single tab character.
</para>
</sect2>
</sect1>
|