0

I'm learning Volley library in android. I'm using JsonObjectRequest for passing JsonObject as request parameters, And I'm getting response as a JsonArray in error listener code for JsonObjectRequest check line no.84 in image Error in Logcat.

Can anyone help me regarding this, how to get JsonArray as response by passing JsonObject as request parameter.

NandhiniB
  • 77
  • 1
  • 12

1 Answers1

2

Use JsonArrayRequest to capture Array in Response

JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(
                            Request.Method.POST,
                            "http://lanes-dev.cloudapp.net/api/DiaryTweetLineApi/LoadDiaryTweetLinesByUser",
                            obj,
                            new Response.Listener<JSONArray>() {
                                @Override
                                public void onResponse(JSONArray response) {

                                }
                            },
                            new Response.ErrorListener(){
                                @Override
                                public void onErrorResponse(VolleyError error){
                                    // Do something when error occurred

                                }
                            }
                    );
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
  • Thanks, I tried using JsonArrayRequest but it is not accepting jsonobject as parameter. – NandhiniB Aug 18 '17 at 04:19
  • [link](https://stackoverflow.com/questions/33014210/how-to-post-request-parameters-when-using-jsonarrayrequest-in-volley) solved my problem :) – NandhiniB Aug 18 '17 at 04:20