Problem with PHP json_decode() and prototype.js .toJSON() function
Jan.15, 2008 in
Development
I have been tearing my hair out trying to work out why PHP’s json_decode() function wouldn’t convert a JSON string sent via AJAX using the prototype.js .toJSON() function. I was sending the string:
{\"Assembly_ID\": 1}
However json_decode() in php would return NULL. After some fiddling around, I determined that json_decode() doesn’t like the “\” characters. Modifying the string as follows solved the problem:
{"Assembly_ID": 1}
The reason they were being sent incorrectly in the first place was because of the option in php.ini:
magic_quotes_gpc = On
Change this setting to “Off” and it all works!

Leave a Reply