2014-09-27 76 views
1

從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()。如何在數組中提取數組中的數組值?謝謝。

回答

1

只需將您的陣列編碼爲JSONArray並將其發佈到您的PHP服務器,使用這種方式更容易。

CallWebServiceTask task = new CallWebServiceTask(6, this, 
       "Fetching Data From Server"); 
task.addNameValuePair("ids", new JSONArray(localIds)); 
task.execute(url); 
+0

究竟如何?我不使用名稱值對嗎? – Kraken 2014-09-27 18:21:22

+0

是的,使用它,擺脫循環,因爲你正在覆蓋郵政鑰匙 – meda 2014-09-27 18:22:20

+0

所以,你想我發送{id1:1,id2:2,id3:3},而不是{ids:1,2,3}? – Kraken 2014-09-27 18:24:47

0
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);