Zend_Json-Basics.xml 1.7 KB

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