Zend_Json-Basics.xml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 19912 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.json.basics">
  5. <title>Uso Básico</title>
  6. <para>
  7. El uso de
  8. <classname>Zend_Json</classname>
  9. consiste en utilizar los dos métodos públicos
  10. estáticos disponibles:
  11. <methodname>Zend_Json::encode()</methodname>
  12. y
  13. <methodname>Zend_Json::decode()</methodname>
  14. .
  15. </para>
  16. <programlisting language="php"><![CDATA[
  17. // Recuperar un valor:
  18. $phpNative = Zend_Json::decode($encodedValue);
  19. // Codificarlo para regresarlo al cliente:
  20. $json = Zend_Json::encode($phpNative);
  21. ]]></programlisting>
  22. <sect2 id="zend.json.basics.prettyprint">
  23. <title>Pretty-printing JSON</title>
  24. <para>
  25. Sometimes, it may be hard to explore
  26. <acronym>JSON</acronym>
  27. data generated by
  28. <methodname>Zend_Json::encode()</methodname>
  29. ,
  30. since it has no spacing or indentation. In order to make it easier,
  31. <classname>Zend_Json</classname>
  32. allows you to pretty-print
  33. <acronym>JSON</acronym>
  34. data in the human-readable format
  35. with
  36. <methodname>Zend_Json::prettyPrint()</methodname>
  37. .
  38. </para>
  39. <programlisting language="php"><![CDATA[
  40. // Encode it to return to the client:
  41. $json = Zend_Json::encode($phpNative);
  42. if($debug) {
  43. echo Zend_Json::prettyPrint($json, array("indent" => " "));
  44. }
  45. ]]></programlisting>
  46. <para>
  47. Second optional argument of
  48. <methodname>Zend_Json::prettyPrint()</methodname>
  49. is an option array.
  50. Option
  51. <code>indent</code>
  52. allows to set indentation string - by default it's a single tab character.
  53. </para>
  54. </sect2>
  55. </sect1>