json_encode error “missing ] after element list” with jquery json plugin
February 8th, 2009
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.
Entry Filed under: Uncategorized
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackback this post | Subscribe to the comments via RSS Feed