vendredi 17 avril 2015

php json_encode() adds an extra character zero at the end

long time reader etc...


I'm trying to parse a simple php associative array to javascript using json_encode, but for some unknown reason, the end result has an extra zero (0) on the end. I've looked around but can't find an answer anywhere, does anyone know what might be happening? This is a call-back from an AJAX call. I simplified teh array to ensure it wasn't my array structure and it still persists.



$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);


Produces



"{"a":1,"b":2,"c":3,"d":4,"e":5}0"


note the extra 0 on the end, which is causing jQuery.parseJSON to throw an error. I'm using Google Chrome for javascript debugging, and PHP with NetBeans, Wamp, in Wordpress.


Many thanks in advance!


Aucun commentaire:

Enregistrer un commentaire