Skip to content

Instantly share code, notes, and snippets.

@EvlinLee
Created June 13, 2014 15:51
Show Gist options
  • Save EvlinLee/4db00f11171c0292bcdb to your computer and use it in GitHub Desktop.
Save EvlinLee/4db00f11171c0292bcdb to your computer and use it in GitHub Desktop.
android volley jsonarray post method with params
public class JsonArrayPostRequest extends Request<JSONArray>{
private Map<String,String> mParam;
private Listener<JSONArray> mListener;
public JsonArrayPostRequest(String url,Listener<JSONArray> listener, ErrorListener errorListener,Map param) {
super(Request.Method.POST, url, errorListener);
mListener=listener;
mParam=param;
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return mParam;
}
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString =
new String(response.data, HttpHeaderParser.parseCharset(response.headers));
return Response.success(new JSONArray(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
@Override
protected void deliverResponse(JSONArray response) {
mListener.onResponse(response);
}
}
@eggysudianto
Copy link

I have jsonArrayRequest = new JsonArrayRequest(GET_JSON_DATA_HTTP_URL, in class RiwayatActivity, and your code must create new class for send a post.. so how to I call that new class in RiwayatActivity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment