I have a JS function that passes a json string to a PHP script via GET using JSON.stringify.
The JSON decodes in the PHP end just fine when on my localhost, but as soon as I moved it to my webserver, it stopped working. Further analysis revealed that my webserver was adding \ (slashes) to the JSON string and according to JSONLint.com, the string with slashes is invalid JSON.
The JSON on my webserver shows up like this:
{\"Product\":\"Walnut Pastry\",\"Size\":\"Slice\",\"Quantity\":\"2\",\"Price\":0}
Why does this happen on my webserver, and what can I do to escape the strings?
I tried json_decode(str_replace('/','',$_GET['json']),true); but that didn’t work either
It appears that you have magic quotes on. Read Magic Quotes
Also you should take note of the warning on the manual page, and then turn it off.