If you are having trouble calling the API, this will help you.
RequestQueue queue = Volley.newRequestQueue(this); JsonObjectRequest jobReq = new JsonObjectRequest(Request.Method.POST, url, jObject, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }); queue.add(jobReq);
where jObject is the JSON data you want to send to the server.
The implementation will be similar for JSONArray. Instead of JsonObjectRequest use JsonArrayRequest and send jArray instead of jObject.
To create a json array, just tweak it a bit
JSONArray array=new JSONArray(); for(int i=0;i<filter_items.size();i++){ JSONObject obj=new JSONObject(); try { obj.put("filterId",filter_items.get(i)); obj.put("typeName","CAT_ID"); } catch (JSONException e) { e.printStackTrace(); } array.put(obj); }
And finally add json array as below
jsonParams.put("filter",array);
In your case, you convert a Json array to a string
source share