Zend_Json-Basics.xml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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> El uso de <classname>Zend_Json</classname> consiste en utilizar los
  7. dos métodos públicos estáticos disponibles:
  8. <methodname>Zend_Json::encode()</methodname> y
  9. <methodname>Zend_Json::decode()</methodname> . </para>
  10. <programlisting language="php"><![CDATA[
  11. // Recuperar un valor:
  12. $phpNative = Zend_Json::decode($encodedValue);
  13. // Codificarlo para regresarlo al cliente:
  14. $json = Zend_Json::encode($phpNative);
  15. ]]></programlisting>
  16. <sect2 id="zend.json.basics.prettyprint">
  17. <title>Pretty-printing JSON</title>
  18. <para> Sometimes, it may be hard to explore <acronym>JSON</acronym> data
  19. generated by <methodname>Zend_Json::encode()</methodname> , since it
  20. has no spacing or indentation. In order to make it easier,
  21. <classname>Zend_Json</classname> allows you to pretty-print
  22. <acronym>JSON</acronym> data in the human-readable format with
  23. <methodname>Zend_Json::prettyPrint()</methodname> . </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> Second optional argument of
  32. <methodname>Zend_Json::prettyPrint()</methodname> is an option
  33. array. Option <code>indent</code> allows to set indentation string -
  34. by default it's a single tab character. </para>
  35. </sect2>
  36. </sect1>