我已经创建了一个Android应用,并且想要将对象数组发送到我的php后端服务器。
对象的JSON数组如下:
[{"a":1,"b":2,"c":3,"d":4}]
我如何在后端服务器上收到此消息?
我尝试过:
1)
$json = file_get_contents('php://input');
$dataer = json_decode($json,true);
$a = $dataer[0]['a'];
$b = $dataer[1]['b'];
$c = $dataer[2]['c'];
$d = $dataer[3]['d'];
2)
$json = file_get_contents('php://input');
$dataer = json_decode($json); ///with $json,true too
var_dump($dataer);
$a = $dataer->a;
$b = $dataer->b;
$c = $dataer->c;
$d = $dataer->d;
我也尝试过使用$_POST['a']
,但没有尝试。
已修复(铃声注释*)
$json = file_get_contents('php://input');
$dataer = json_decode($json,true);
$a = $dataer[0]->a;
$b = $dataer[0]->b;
$c = $dataer[0]->c;
$d = $dataer[0]->d;