|
|
@@ -2,11 +2,13 @@
|
|
|
<!-- Reviewed: no -->
|
|
|
<sect1 id="zend.json.basics">
|
|
|
<title>Basic Usage</title>
|
|
|
+
|
|
|
<para>
|
|
|
Usage of <classname>Zend_Json</classname> involves using the two public static
|
|
|
methods available: <methodname>Zend_Json::encode()</methodname> and
|
|
|
<methodname>Zend_Json::decode()</methodname>.
|
|
|
</para>
|
|
|
+
|
|
|
<programlisting language="php"><![CDATA[
|
|
|
// Retrieve a value:
|
|
|
$phpNative = Zend_Json::decode($encodedValue);
|
|
|
@@ -16,26 +18,29 @@ $json = Zend_Json::encode($phpNative);
|
|
|
]]></programlisting>
|
|
|
|
|
|
<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[
|
|
|
+ <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" => " "));
|
|
|
+ echo Zend_Json::prettyPrint($json, array("indent" => " "));
|
|
|
}
|
|
|
]]></programlisting>
|
|
|
- <para>
|
|
|
- Second optional argument of <methodname>Zend_Json::prettyPrint()</methodname> is an option array.
|
|
|
- Option <code>indent</code> allows to set indentation string - by default it's a single tab character.
|
|
|
- </para>
|
|
|
- </sect2>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ Second optional argument of <methodname>Zend_Json::prettyPrint()</methodname> is an option array.
|
|
|
+ Option <code>indent</code> allows to set indentation string - by default it's a single tab character.
|
|
|
+ </para>
|
|
|
+ </sect2>
|
|
|
</sect1>
|
|
|
<!--
|
|
|
vim:se ts=4 sw=4 et:
|