If you’re using the excellent jquery json plugin you might run into problems trying to parse json returned from the php function json_encode.
Specifically, when you try to parse the returned json using $.evalJSON you get the javascript error
missing ] after element list
I also had this same problem with the cakephp json component (which I decided to use instead since it would be more portable across php versions than the php5.2+ only json_encode).
The simple fix is this.
Add slashes to your output and surround it with double quotes like this …
$status = json_encode($status); echo '"'.addslashes($status).'"'; |
I figured this one out, by examining rails json output that worked just fine with the jquery json plugin.