Reputation: 71
I have a php webservice that returns a json array using json_encode(array("moviemakers"=>$rows)).
I need to make the json array request from android with parameters.
I saw this:
public JsonArrayRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONArray> listener, ErrorListener errorListener) {
super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(),
listener, errorListener);
}
When I use it in my code, it generates an error.
Could anyone guide me where to put the above snippet in my code?
Upvotes: 1
Views: 721
Reputation: 462
Here an example of a JsonObjectRequest:
private void volleyRequest(String url){
final JsonObjectRequest request = new JsonObjectRequest(url, null, new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject response) {
try {
Log.i(LOG_FLAG, response.toString(4));
//parseJSON
}catch (JSONException e){
//handle exception
}
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError volleyError) {
//handle error
}
});
//adding request into the queue
ApplicationClass.getInstance().addToRequestQueue(request,"someTag");
}
here you can find a really nice tutorial about volley: Asynchronous HTTP Requests in Android Using Volley
Upvotes: 1