PHP POST方法json_decode返回NULL

时间:2014-11-01 19:49:33

标签: php json extjs

我使用sencha touch并且我将数据发送到php REST服务器以将其保存到数据库中,在firebug中我可以看到sencha touch发送到php端的参数,但在php中我有这个代码:

parse_str(file_get_contents("php://input"),$post_vars);
$info=$post_vars['customers'];
$data=json_decode(stripslashes($info),true);

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"}"
    }

在var_dump帖子包含:

之前,我不知道如何继续
{"success":{"customers":"{\"c_name\":\"test\",\"c_tel\":\"08-05852821\",\"id\":\"112\"}"}}

我尝试过striplashes但我也得到了NULL ......

任何想法......

2 个答案:

答案 0 :(得分:1)

根据您的评论,我会直接访问$_POST

$info = json_decode($_POST['customers'], true);
echo $info['c_name'];

答案 1 :(得分:0)

杰森如何传播有三种可能性。

  • 首先,它可以是带有Name(index.php?data={success:true})的get变量,这只适用于Short json字符串。
  • 其次,它可以是带有名称的帖子变量(将作为x-www-form-urlencoded发送)
  • 第三,你只能发布json(Store.sync就是这样)

只能通过php://Input访问后者,它似乎是你使用秒。

相关问题