cvs: phpdoc /en/reference/json/functions json-decode.xml

From: Date: Wed, 10 Sep 2008 01:51:18 +0000
Subject: cvs: phpdoc /en/reference/json/functions json-decode.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2156@lists.php.net to get a copy of this message
hradtke Wed Sep 10 01:51:18 2008 UTC Modified files: /phpdoc/en/reference/json/functions json-decode.xml Log: Added an example showing some common problems people using JavaScript run into when using json_decode. Also added a note stating that JSON is not the same as JavaScript in hopes that people will realize that the json_decode function is not buggy but instead following the JSON specification. http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/json/functions/json-decode.xml?r1=1.7&r2=1.8&diff_format=u Index: phpdoc/en/reference/json/functions/json-decode.xml diff -u phpdoc/en/reference/json/functions/json-decode.xml:1.7 phpdoc/en/reference/json/functions/json-decode.xml:1.8 --- phpdoc/en/reference/json/functions/json-decode.xml:1.7 Fri Jul 25 08:48:04 2008 +++ phpdoc/en/reference/json/functions/json-decode.xml Wed Sep 10 01:51:18 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.7 $ --> +<!-- $Revision: 1.8 $ --> <refentry xml:id="function.json-decode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>json_decode</refname> @@ -104,11 +104,41 @@ ]]> </programlisting> </example> + <example> + <title>common mistakes using <function>json_decode</function></title> + <programlisting role="php"> +<![CDATA[ +<?php + +// the following strings are valid JavaScript but not valid JSON + +// the name and value must be enclosed in double quotes +// single quotes are not valid +$bad_json = "{ 'bar': 'baz' }"; +json_decode($bad_json); // null + +// the name must be enclosed in double quotes +$bad_json = '{ bar: "baz" }'; +json_decode($bad_json); // null + +// trailing commas are not allowed +$bad_json = '{ bar: "baz", }'; +json_decode($bad_json); // null + +?> +]]> + </programlisting> + </example> </para> </refsect1> <refsect1 role="notes"> &reftitle.notes; + <note> + <para> + The JSON spec is not JavaScript, but a subset of JavaScript. + </para> + </note> <caution> <para> This function will return false if the JSON encoded data is deeper than

« previous php.doc.cvs (#2156) next »