json_decode()在Web服务器上不起作用 [英] json_decode() not working on the web server
问题描述
我有一个PHP脚本,可以在我的本地主机服务器上正常工作.
I have a php script which is working perfectly on my localhost server.
当我将所有内容从本地主机移到Web服务器时,我的json_decode
无法正常工作.
When I moved everything from the localhost to the web server my json_decode
is not working.
我尝试了json_encode
,仍然没有.
这种行为可能有什么问题?
what could be a problem for such behavior?
我的代码:
$productsArr = json_encode($_GET['object']);
$_GET['object']
是经过验证的JSON.
$_GET['object']
is validated JSON.
我的最后一个选择可能是magic_quotes
,但我不知道是否可以使用cPanel更改PHP.ini文件,而cPanel是我对服务器的唯一访问权限.
My last option could be magic_quotes
but I don't know if I can change PHP.ini file using a cPanel which is my only access to the server.
我将不胜感激.
这是我的网址的一部分:
this is part of my url:
Request URL:http://something.com/download.php?object=[{%22code%22:%222F-58S%22},{%22code%22:%22HT-45H%22},{%22code%22:%2244-3%22},{%22code%22:%22898-OPv%22}]&checkbox=
即使这很重要,我也正在使用这些标头:
I'm using this headers if this is even important:
header('Content-Description: File Transfer');
header("Content-type: application/ms-word");
header("Content-Disposition: attachment;Filename=$name_of_file.doc");
推荐答案
我必须这样做才能使json_decode
工作.也许对此有更好的方案.
I had to do this to make json_decode
work. Maybe there is a better scheme for this.
$j = $_POST["json"];
$j = str_replace("\\\\\"", "###dq###", $j);
$j = str_replace("\\", "", $j);
$j = str_replace("###dq###", "\\\"", $j);
或者简而言之:
$j = stripslashes($j);
这篇关于json_decode()在Web服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!