我使用的是sencha touch,我将数据发送到phpREST服务器以将其保存到数据库,在firebug中我可以看到sencha touck发送到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'"}"}}
我试过条纹斜杠,但我也失败了。。。
任何想法。。。
根据您的评论,我将直接访问$_POST
:
$info = json_decode($_POST['customers'], true);
echo $info['c_name'];
Jason的传输方式有三种可能性。
- 首先,它可以是一个名为(
index.php?data={success:true}
)的get变量,这只适用于短json字符串 - 其次,它可以是具有Name的post变量(将作为
x-www-form-urlencoded
发送) - 第三,您只能发布json(Store.sync会这样做)
只有Latter会通过php://Input
访问,似乎你使用的是Second。