note 86358 modified in function.json-encode by rquadling

From: Date: Thu, 19 Mar 2009 16:07:49 +0000
Subject: note 86358 modified in function.json-encode by rquadling
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152153@lists.php.net to get a copy of this message
When Using Libraries such as Prototype you may find that once in a while when you return what you believe to be a empty array it will have a different behavior (vis a vis enumerables) than when you give it an associative array. To "fix" this, on your JS you may want to look for extended object properties to verify if it is an empty array or an ocject. example: if (transport.responseJSON['User'].length == undefined){ var user = $H(transport.responseJSON['User']); }else{ var user = transport.responseJSON['User']; } Thanks goes out to : jani@php.net This is totally expected behaviour. Please read this: http://www.json.org/ Note: array and assoc-array are different things. Latter being "object" in json. http://bugs.php.net/bug.php?id=45162 [RQuadling] See http://bugs.php.net/bug.php?id=47493. Fixed by using json_encode(array(), JSON_FORCE_OBJECT); --was-- When Using Libraries such as Prototype you may find that once in a while when you return what you believe to be a empty array it will have a different behavior (vis a vis enumerables) than when you give it an associative array. To "fix" this, on your JS you may want to look for extended object properties to verify if it is an empty array or an ocject. example: if (transport.responseJSON['User'].length == undefined){ var user = $H(transport.responseJSON['User']); }else{ var user = transport.responseJSON['User']; } Thanks goes out to : jani@php.net This is totally expected behaviour. Please read this: http://www.json.org/ Note: array and assoc-array are different things. Latter being "object" in json. http://bugs.php.net/bug.php?id=45162 http://php.net/manual/en/function.json-encode.php

« previous php.notes (#152153) next »