json_decode可在localhost上使用,但不能在网络服务器上使用 [英] json_decode works on localhost but not on webserver

查看:130
本文介绍了json_decode可在localhost上使用,但不能在网络服务器上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JS函数,它使用JSON.stringify通过GET将json字符串传递给PHP脚本.

I have a JS function that passes a json string to a PHP script via GET using JSON.stringify.

在本地主机上时,PHP中的JSON解码效果很好,但是一旦将其移至Web服务器,它便停止工作.进一步的分析表明,我的网络服务器向JSON字符串添加了\(斜杠),并且根据JSONLint.com,带有斜杠的字符串是无效的JSON.

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.

我的网络服务器上的JSON显示如下:

The JSON on my webserver shows up like this:

{\"Product\":\"Walnut Pastry\",\"Size\":\"Slice\",\"Quantity\":\"2\",\"Price\":0}

为什么这会在我的网络服务器上发生,我该怎么做才能转义字符串? 我尝试了json_decode(str_replace('/','',$_GET['json']),true);,但是那也不起作用

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.

这篇关于json_decode可在localhost上使用,但不能在网络服务器上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆