public class JsonHttpResponseHandler extends TextHttpResponseHandler
AsyncHttpClient, with
automatic parsing into a JSONObject or JSONArray. This class is designed to be passed to get, post, put and delete requests with the
onSuccess(int,
cz.msebera.android.httpclient.Header[], org.json.JSONArray) or onSuccess(int,
cz.msebera.android.httpclient.Header[], org.json.JSONObject) methods anonymously overridden. Additionally, you can override the other event methods from the parent class.
BUFFER_SIZE, CANCEL_MESSAGE, DEFAULT_CHARSET, FAILURE_MESSAGE, FINISH_MESSAGE, PROGRESS_MESSAGE, RETRY_MESSAGE, START_MESSAGE, SUCCESS_MESSAGE, UTF8_BOM| Constructor and Description |
|---|
JsonHttpResponseHandler()
Creates new JsonHttpResponseHandler, with JSON String encoding UTF-8
|
JsonHttpResponseHandler(boolean useRFC5179CompatibilityMode)
Creates new JsonHttpResponseHandler with JSON String encoding UTF-8 and given RFC5179CompatibilityMode
|
JsonHttpResponseHandler(java.lang.String encoding)
Creates new JsonHttpResponseHandler with given JSON String encoding
|
JsonHttpResponseHandler(java.lang.String encoding,
boolean useRFC5179CompatibilityMode)
Creates new JsonHttpResponseHandler with given JSON String encoding and RFC5179CompatibilityMode
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isUseRFC5179CompatibilityMode() |
void |
onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] responseBytes,
java.lang.Throwable throwable)
Fired when a request fails to complete, override to handle in your own code
|
void |
onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.String responseString,
java.lang.Throwable throwable)
Called when request fails
|
void |
onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.Throwable throwable,
org.json.JSONArray errorResponse)
Returns when request failed
|
void |
onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.Throwable throwable,
org.json.JSONObject errorResponse)
Returns when request failed
|
void |
onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] responseBytes)
Fired when a request returns successfully, override to handle in your own code
|
void |
onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
org.json.JSONArray response)
Returns when request succeeds
|
void |
onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
org.json.JSONObject response)
Returns when request succeeds
|
void |
onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.String responseString)
Called when request succeeds
|
protected java.lang.Object |
parseResponse(byte[] responseBody)
Returns Object of type
JSONObject, JSONArray, String, Boolean, Integer, Long,
Double or JSONObject.NULL, see JSONTokener.nextValue() |
void |
setUseRFC5179CompatibilityMode(boolean useRFC5179CompatibilityMode) |
getResponseStringgetCharset, getRequestHeaders, getRequestURI, getTag, getUsePoolThread, getUseSynchronousMode, handleMessage, obtainMessage, onCancel, onFinish, onPostProcessResponse, onPreProcessResponse, onProgress, onRetry, onStart, onUserException, postRunnable, sendCancelMessage, sendFailureMessage, sendFinishMessage, sendMessage, sendProgressMessage, sendResponseMessage, sendRetryMessage, sendStartMessage, sendSuccessMessage, setCharset, setRequestHeaders, setRequestURI, setTag, setUsePoolThread, setUseSynchronousModepublic JsonHttpResponseHandler()
public JsonHttpResponseHandler(java.lang.String encoding)
encoding - String encoding to be used when parsing JSONpublic JsonHttpResponseHandler(boolean useRFC5179CompatibilityMode)
useRFC5179CompatibilityMode - Boolean mode to use RFC5179 or latestpublic JsonHttpResponseHandler(java.lang.String encoding,
boolean useRFC5179CompatibilityMode)
encoding - String encoding to be used when parsing JSONuseRFC5179CompatibilityMode - Boolean mode to use RFC5179 or latestpublic void onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
org.json.JSONObject response)
statusCode - http response status lineheaders - response headers if anyresponse - parsed response if anypublic void onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
org.json.JSONArray response)
statusCode - http response status lineheaders - response headers if anyresponse - parsed response if anypublic void onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.Throwable throwable,
org.json.JSONObject errorResponse)
statusCode - http response status lineheaders - response headers if anythrowable - throwable describing the way request failederrorResponse - parsed response if anypublic void onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.Throwable throwable,
org.json.JSONArray errorResponse)
statusCode - http response status lineheaders - response headers if anythrowable - throwable describing the way request failederrorResponse - parsed response if anypublic void onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.String responseString,
java.lang.Throwable throwable)
TextHttpResponseHandleronFailure in class TextHttpResponseHandlerstatusCode - http response status lineheaders - response headers if anyresponseString - string response of given charsetthrowable - throwable returned when processing requestpublic void onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
java.lang.String responseString)
TextHttpResponseHandleronSuccess in class TextHttpResponseHandlerstatusCode - http response status lineheaders - response headers if anyresponseString - string response of given charsetpublic final void onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] responseBytes)
AsyncHttpResponseHandleronSuccess in class TextHttpResponseHandlerstatusCode - the status code of the responseheaders - return headers, if anyresponseBytes - the body of the HTTP response from the serverpublic final void onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] responseBytes,
java.lang.Throwable throwable)
AsyncHttpResponseHandleronFailure in class TextHttpResponseHandlerstatusCode - return HTTP status codeheaders - return headers, if anyresponseBytes - the response body, if anythrowable - the underlying cause of the failureprotected java.lang.Object parseResponse(byte[] responseBody)
throws org.json.JSONException
JSONObject, JSONArray, String, Boolean, Integer, Long,
Double or JSONObject.NULL, see JSONTokener.nextValue()responseBody - response bytes to be assembled in String and parsed as JSONorg.json.JSONException - exception if thrown while parsing JSONpublic boolean isUseRFC5179CompatibilityMode()
public void setUseRFC5179CompatibilityMode(boolean useRFC5179CompatibilityMode)