从android发送数组到php。 $ _ POST显示阵列()字符串
问题描述:
从Android的电话如下:
CallWebServiceTask task = new CallWebServiceTask(6, this,
"Fetching Data From Server");
int key = 0;
for(int i = 0; i < localIds.size(); i++) {
key = localIds.keyAt(i);
// get the object by the key.
task.addNameValuePair("ids", ""+key);
}
task.execute(url);
这一个将ID列表添加到关键ids
。
在我的php上,当我这样做时,print_r($_POST);
它只返回一个字符串作为Array()
。如何在数组中提取数组中的数组值?谢谢。
答
只需将您的阵列编码为JSONArray
并将其发布到您的PHP
服务器,使用这种方式更容易。
CallWebServiceTask task = new CallWebServiceTask(6, this,
"Fetching Data From Server");
task.addNameValuePair("ids", new JSONArray(localIds));
task.execute(url);
答
CallWebServiceTask task = new CallWebServiceTask(6, this,
"Fetching Data From Server");
int key = 0;
for(int i = 0; i < localIds.size(); i++) {
key = localIds.keyAt(i);
// get the object by the key.
task.addNameValuePair("ids"+i, ""+key);
}
task.execute(url);
究竟如何?我不使用名称值对吗? – Kraken 2014-09-27 18:21:22
是的,使用它,摆脱循环,因为你正在覆盖邮政钥匙 – meda 2014-09-27 18:22:20
所以,你想我发送{id1:1,id2:2,id3:3},而不是{ids:1,2,3}? – Kraken 2014-09-27 18:24:47