Last active
August 29, 2015 14:02
-
-
Save EvlinLee/97bbac0206032590c0ec to your computer and use it in GitHub Desktop.
android volley json post method with params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JsonObjectPostRequest extends Request<JSONObject>{ | |
private Map<String,String> mParam; | |
private Listener<JSONObject> mListener; | |
public JsonObjectPostRequest(String url,Listener<JSONObject> 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<JSONObject> parseNetworkResponse(NetworkResponse response) { | |
try { | |
String jsonString = | |
new String(response.data, HttpHeaderParser.parseCharset(response.headers)); | |
return Response.success(new JSONObject(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(JSONObject response) { | |
mListener.onResponse(response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment