Reputation: 15
So heres my stuff basic getParams post method in volley but I don't know how to send array to backend can someone help?
@Override
protected Map<String, String> getParams() {
JSONObject jsonObject = new JSONObject();
//looping throught recyclerview
for (int i = 0; i < CustomCreateGroupAdapter.dataModelArrayList.size(); i++){
//getting selected items
if(CustomCreateGroupAdapter.dataModelArrayList.get(i).getSelected()) {
try {
//putting all user ids who you selected into jsonObject
jsonObject.put("params", CustomCreateGroupAdapter.dataModelArrayList.get(i).getOthersid());
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Map<String, String> params = new HashMap<String, String>();
params.put("params",jsonObject.toString());
return params;
}
Upvotes: 0
Views: 198
Reputation: 8870
Add the objects of your payload to a JSONArray, then use JSONArray.toString()
to pass the payload to a JsonRequest as the requestBody
.
Upvotes: 0
Reputation: 654
You should add all those values to a JSONArray and then add this JSONArray to your JSONObject. You could also add all objects to a simple array and then get the corresponding JSONArray by calling new JSONArray(your_array);
Upvotes: 1