How to send json array as post request in volley?

后端 未结 6 1413
孤城傲影
孤城傲影 2021-01-04 08:56

I am using volley for json parsing. I want to send some data using POST to server side. I am trying to send .Now can any one tell me that how can i send filter array to serv

6条回答
  •  别那么骄傲
    2021-01-04 09:56

    If you are having a problem in calling the API then this will help you.

    RequestQueue queue = Volley.newRequestQueue(this);
    JsonObjectRequest jobReq = new JsonObjectRequest(Request.Method.POST, url, jObject,
            new Response.Listener() {
                @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.

    Implementation will be similar for JSONArray. Instead of JsonObjectRequest use JsonArrayRequest and send jArray instead of jObject.

    For creating json array just do a little tweak

    JSONArray array=new JSONArray();
    
    for(int i=0;i

    And finally add json array as below

    jsonParams.put("filter",array);
    

    In your case you are converting Json array to string

提交回复
热议问题