JSON not properly supported by Joomla, falls back to INI

This forum is for reporting bugs in Joomla!. Please don't report problems with extensions in here.
Locked
JesperHansen
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Mar 22, 2012 8:44 am

JSON not properly supported by Joomla, falls back to INI

Post by JesperHansen » Thu Mar 22, 2012 8:56 am

Joomla does not support JSON properly.

Code: Select all

$this->lessons = "[2,14,35,25,24]"; // fetched from database normally
print_r($this->lessons);
// Output: [2,14,35,25,24]
$lessons = new JRegistry;
$lessons->loadJSON($this->lessons);
$this->lessons = $lessons;

print_r($this->lessons);
// Output: JRegistry Object ( [data:protected] => stdClass Object ( ) ) 
echo $this->lessons;
// Output: {}
A php.net example of how it should work: @ http://php.net/manual/en/function.json-encode.php

Code: Select all

$a = array('<foo>',"'bar'",'"baz"','&blong&', "\xc3\xa9");
echo "Normal: ",  json_encode($a), "\n";
// Output: Normal: ["<foo>","'bar'","\"baz\"","&blong&","\u00e9"]
This is probably caused by this: http://hg.joomla.org/joomla-platform/sr ... .php#cl-46
It assumes JSON is only objects {}.

Although we have access to functions like loadArray then this function does not work like json_decode/encode.
A echo output of loadArray: {"0":"[2,14,35,25,24]"}

JesperHansen
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Mar 22, 2012 8:44 am

Re: JSON not properly supported by Joomla, falls back to INI

Post by JesperHansen » Thu Mar 22, 2012 8:57 am

Could this be moved to 2.5 bug reporting? Thanks


Locked

Return to “Joomla! 1.5 Bug Reporting”