note 82380 added to function.json-decode

From: Date: Tue, 08 Apr 2008 21:04:08 +0000
Subject: note 82380 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-138034@lists.php.net to get a copy of this message
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 :) ---- Server IP: 202.89.58.1 Probable Submitter: 60.234.168.92 ---- Manual Page -- http://www.php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/82380 Del: integrated -- https://master.php.net/note/delete/82380/integrated Del: useless -- https://master.php.net/note/delete/82380/useless Del: bad code -- https://master.php.net/note/delete/82380/bad+code Del: spam -- https://master.php.net/note/delete/82380/spam Del: non-english -- https://master.php.net/note/delete/82380/non-english Del: in docs -- https://master.php.net/note/delete/82380/in+docs Del: other reasons-- https://master.php.net/note/delete/82380 Reject -- https://master.php.net/note/reject/82380 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138034) next »