简体   繁体   中英

android volley how to send array?

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;
    }

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

将有效负载的对象添加到JSONArray ,然后使用JSONArray.toString()将有效负载作为requestBody传递给JsonRequest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM