parseJson behaves differently under PHP 5.0
Folks, I am doing some AJAX stuff and it looks like parseJson may be handling arrays differently between PHP 4.x and 5.x. When using parseJson this is dumped under PHP 4.x { 0: { 0: "47", 1: "-122", 2: "Mr Dan Robinson" }, 1: { 0: "47.5", 1: "-122.5", 2: "dan@foobar.org" }, 2: { 0: "47.75", 1: "-122.6", 2: "George Robinson" } } and this in 5.x [ [ "44.4966", "-75.073", "Mr Anne C Jones Jr" ], [ "32.2153", "-98.208", "Mrs Sheila X Yadav Sr" ], [ "34.9967", "-85.2375", "Dr Michael M Patel Jr" ] ] Different data obviously - same code. Hints appreciated, Dan
Looks like sequential arrays are converted to JS objects in PHP 4. Still, due to the array/object duality in JS, this is not that much of a problem. Just something to look at later. Steven Wittens
hmmm... Well my code works under 4.x and not under 5.x - so it is different. I'm just starting to understand all this so I'm a little lost. My current code does this: function addContactsToMap(httpresponse, xmlhttp, contacts) { if (xmlhttp.status != 200) { alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ httpresponse); } ; map.clearOverlays(); var parsed = parseJson(httpresponse); for ( x in parsed ) { addContactToMap(parsed[x][0], parsed[x][1], parsed[x][2]); } } suggestions about what to do to get this to work under 5.x? Thanks, Dan
Looks like sequential arrays are converted to JS objects in PHP 4. Still, due to the array/object duality in JS, this is not that much of a problem. Just something to look at later.
Steven Wittens
There's an outstanding bug in parseJson, see this issue:
There's an outstanding bug in parseJson, see this issue:
http://drupal.org/node/59038 (somehow sent that when I was trying to paste in.) You can try overriding the parseJson in drupal.js with the patched version and see if that solves the problem.
yes - that fixed my problem - thanks. Dan
There's an outstanding bug in parseJson, see this issue:
(somehow sent that when I was trying to paste in.)
You can try overriding the parseJson in drupal.js with the patched version and see if that solves the problem.
The problem is not parseJson I think, but the PHP function drupal_to_js(). Check why its array detection is failing, and see if you can fix it ;). Steven Wittens
Actually, the keys are completely lost. 2006/5/2, Steven Wittens <steven@acko.net>:
Looks like sequential arrays are converted to JS objects in PHP 4. Still, due to the array/object duality in JS, this is not that much of a problem. Just something to look at later.
Steven Wittens
participants (4)
-
Dan Robinson -
Konstantin Käfer -
Nedjo Rogers -
Steven Wittens