简体   繁体   English

Android Volley如何发送数组?

[英]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? 所以这是我在volley中的基本getParams post方法的继承人,但是我不知道如何将数组发送到后端可以有人帮助吗?

@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. 您应该将所有这些值添加到JSONArray ,然后将此JSONArray添加到您的JSONObject。 You could also add all objects to a simple array and then get the corresponding JSONArray by calling new JSONArray(your_array); 您还可以将所有对象添加到一个简单的数组中,然后通过调用new JSONArray(your_array);获得相应的JSONArray new JSONArray(your_array);

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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