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: {}
Code: Select all
$a = array('<foo>',"'bar'",'"baz"','&blong&', "\xc3\xa9");
echo "Normal: ", json_encode($a), "\n";
// Output: Normal: ["<foo>","'bar'","\"baz\"","&blong&","\u00e9"]
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]"}