Reputation: 550
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:
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:
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:
{"success":{"customers":"{\"c_name\":\"test\",\"c_tel\":\"08-05852821\",\"id\":\"112\"}"}}
I tried stripslashes but I got also NULL...
Any idea...
Upvotes: 0
Views: 711
Reputation: 20234
There are three possibilities how Jason can be transmitted.
index.php?data={success:true}
), this only Works for Short json strings.x-www-form-urlencoded
)Only the Latter will be accessed via php://Input
, it Seems as of you use the Second.
Upvotes: 0
Reputation: 91762
Based on your comment, I would access $_POST
directly:
$info = json_decode($_POST['customers'], true);
echo $info['c_name'];
Upvotes: 1