[英]PHP POST method json_decode return NULL
I'm using sencha touch and I'm sending data to php REST server to save it to database, in firebug I can see the parameters that sencha touch send to php side, but in php I have this code: 我正在使用sencha touch,并且正在将数据发送到php REST服务器以将其保存到数据库,在萤火虫中,我可以看到sencha touch发送到php端的参数,但是在php中,我有以下代码:
parse_str(file_get_contents("php://input"),$post_vars);
$info=$post_vars['customers'];
$data=json_decode(stripslashes($info),true);
The json_decode return NULL, the get_magic_quotes_gpc is off I also tried utf8_encode but always I got NULL, I tried var_dump and at the response I got extra text: json_decode返回NULL,get_magic_quotes_gpc处于关闭状态,我也尝试过utf8_encode,但始终我得到NULL,我尝试了var_dump,并在响应时得到了额外的文本:
array(1) {
["customers"]=>
string(50) "{"c_name":"test","c_tel":"08-05852821","id":"112"}"
}
I don't know how to continue, before the var_dump the post contains: 在var_dump包含以下内容之前,我不知道如何继续:
{"success":{"customers":"{\"c_name\":\"test\",\"c_tel\":\"08-05852821\",\"id\":\"112\"}"}}
I tried stripslashes but I got also NULL... 我尝试了反斜杠,但我也得到了NULL ...
Any idea... 任何想法...
Based on your comment, I would access $_POST
directly: 根据您的评论,我将直接访问$_POST
:
$info = json_decode($_POST['customers'], true);
echo $info['c_name'];
There are three possibilities how Jason can be transmitted. Jason的传输方式有三种。
index.php?data={success:true}
), this only Works for Short json strings. 首先,它可以是带有名称的get变量( index.php?data={success:true}
),这仅适用于Short json字符串。 x-www-form-urlencoded
) 其次,它可以是带有Name的post变量(将发送为x-www-form-urlencoded
) Only the Latter will be accessed via php://Input
, it Seems as of you use the Second. 只有后期可以通过php://Input
访问,似乎在您使用Second时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.