note 82380 deleted from function.json-decode by danbrown
| From: | danbrown@php.net | Date: | Sat, 02 May 2009 14:55:31 +0000 |
| Subject: | note 82380 deleted from function.json-decode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154141@lists.php.net to get a copy of this message | ||
Note Submitter: Hayley Watson
----
In relation to yasarbayar's comment:
Remember that JSON strings are JavaScript code and have JavaScript syntax. In PHP, arrays and
associative arrays are the same thing but that's not true in JavaScript, where
"associative arrays" are really objects. [] is an array initializer, {} creates objects:
{30:'13',31:'14',32:'15'}
Bad: JavaScript object initialiser, but object property names can't be integers.
{[30:'13',31:'14',32:'15']}
{["30":"13","31":"14","32":"15"]}
Bad: JavaScript object initializer, but a JavaScript array is not a valid property name. Also,
JavaScript arrays are not
associative, and their initializers do not use object property syntax to specify their values.
[{"30":"13","31":"14","32":"15"}]
Good: An array initializer with a single element; that element is initialized as an object with
properties named "30", "31", "32" and
values "13", "14", "15" (all strings).
"It took me a while to find the right JSON string format...."
You could have used json_encode() to do that :)