Reputation: 485
i'm ussing volley to send post requests to my php backend but i'm unable to pass an array as parameters... or add multiple parameters with the same name which only add the last param in the for loop to the params
this code works but only return the last number as parameter and not both numbers:
protected Map<String, String> getParams() {
ArrayList<String> numbers = new ArrayList<String>();
numbers.add("+431111111111");
numbers.add("+432222222222");
Map<String, String> params = new HashMap<String, String>();
for(String object: numbers){
params.put("friendnr[]", object);
}
return params;
}
i just want to pass an array, list of "friendnr" to my php backend..
thx
Upvotes: 2
Views: 7680
Reputation: 1768
your for each loop is buggy...
protected Map<String, String> getParams() {
ArrayList<String> numbers = new ArrayList<String>();
numbers.add("+431111111111");
numbers.add("+432222222222");
Map<String, String> params = new HashMap<String, String>();
int i=0;
for(String object: numbers){
params.put("friendnr["+(i++)+"]", object);
// you first send both data with same param name as friendnr[] .... now send with params friendnr[0],friendnr[1] ..and so on
}
return params;
}
Upvotes: 8