Zend_Json-Basics.xml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 22432 -->
  4. <sect1 id="zend.json.basics">
  5. <title>基本的な使用法</title>
  6. <para>
  7. <classname>Zend_Json</classname> を使用するために、
  8. 静的な publicメソッドが 2 つ公開されています。
  9. 名前は <methodname>Zend_Json::encode()</methodname> および
  10. <methodname>Zend_Json::decode()</methodname> となります。
  11. </para>
  12. <programlisting language="php"><![CDATA[
  13. // 値を取得します
  14. $phpNative = Zend_Json::decode($encodedValue);
  15. // クライアントに返すために、それをエンコードします
  16. $json = Zend_Json::encode($phpNative);
  17. ]]></programlisting>
  18. <sect2 id="zend.json.basics.prettyprint">
  19. <title>Pretty-printing JSON</title>
  20. <para>
  21. Sometimes, it may be hard to explore <acronym>JSON</acronym> data generated by
  22. <methodname>Zend_Json::encode()</methodname>,
  23. since it has no spacing or indentation. In order to make it easier, <classname>Zend_Json</classname>
  24. allows you to pretty-print <acronym>JSON</acronym> data in the human-readable format
  25. with <methodname>Zend_Json::prettyPrint()</methodname>.
  26. </para>
  27. <programlisting language="php"><![CDATA[
  28. // クライアントに返すために、それをエンコードします
  29. $json = Zend_Json::encode($phpNative);
  30. if($debug) {
  31. echo Zend_Json::prettyPrint($json, array("indent" => " "));
  32. }
  33. ]]></programlisting>
  34. <para>
  35. Second optional argument of <methodname>Zend_Json::prettyPrint()</methodname> is an option array.
  36. Option <property>indent</property> allows to set indentation string - by default it's a single tab character.
  37. </para>
  38. </sect2>
  39. </sect1>
  40. <!--
  41. vim:se ts=4 sw=4 et:
  42. -->