[prev in list] [next in list] [prev in thread] [next in thread]
List: php-doc-cvs
Subject: [DOC-CVS] cvs: phpdoc /en/reference/json/functions json-decode.xml
From: "Herman Radtke" <hradtke () php ! net>
Date: 2008-09-10 1:51:18
Message-ID: cvshradtke1221011478 () cvsserver
[Download RAW message or body]
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
--
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic