I would like to send and receive a Json Array with volley. Now I can receive an array and it's ok but I don't know how to send a request (For example: with post method).
JsonArrayRequest arrayReq = new JsonArrayRequest(URL,
new Listener<JSONArray>() {
}
Create a class and extend JsonArrayRequest then override
Create a new java class named JsonArrayPostRequest now you can use it like the previous request, just replace JSONArrayRequest with JsonArrayPostRequest and pass the correct parameters
USE:
Here is an example:
How the POST request differs is that it takes a
JSONObject
as parameter.EDIT 1:
If you have
Volley
installed as a library project in your IDE, then just define a new constructorinside the class
JsonArrayRequest
which is present in theVolley
library code. Now you can use this to createJsonArrayRequest
objects and add them to theRequestQueue
.EDIT 2:
1. Get the Volley library project from here. Download the project and set it up in your IDE.
2. Make the modification to the
JsonRequest
class (found incom.android.volley.toolbox
namespace) as discussed in EDIT 1.3. Delete the
volley.jar
from thelibs
folder of your APPLICATION PROJECT.4. Now go to Project Properties -> Android -> Library and click on Add. From here select the
Volley
project. Clean & Rebuild.5. Now in your APPLICATION PROJECT you can make a POST
JsonArrayRequest
just like how we make a POSTJsonObjectRequest
and get aJSONArray
in theResponse
.