Archive for February 8th, 2009

json_encode error “missing ] after element list” with jquery json plugin

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.

Add comment February 8th, 2009


I recommend

Linode VPS's for Rails hosting
Heroku for mindless Rails hosting
Site 5 for shared Rails hosting and all round great service

Posts by Category

Calendar

February 2009
S M T W T F S
« Dec   Apr »
1234567
891011121314
15161718192021
22232425262728

Posts by Month