@@ -146,18 +146,29 @@ public void onSuccess(final int statusCode, final Header[] headers, final byte[]
146
146
@ Override
147
147
public void run () {
148
148
try {
149
- Object jsonResponse = parseResponse (responseBody );
150
- if (jsonResponse instanceof JSONObject ) {
151
- onSuccess (statusCode , headers , (JSONObject ) jsonResponse );
152
- } else if (jsonResponse instanceof JSONArray ) {
153
- onSuccess (statusCode , headers , (JSONArray ) jsonResponse );
154
- } else if (jsonResponse instanceof String ) {
155
- onSuccess (statusCode , headers , (String ) jsonResponse );
156
- } else {
157
- onFailure (new JSONException ("Unexpected type " + jsonResponse .getClass ().getName ()), (JSONObject ) null );
158
- }
159
- } catch (JSONException ex ) {
160
- onFailure (ex , (JSONObject ) null );
149
+ final Object jsonResponse = parseResponse (responseBody );
150
+ postRunnable (new Runnable () {
151
+ @ Override
152
+ public void run () {
153
+ if (jsonResponse instanceof JSONObject ) {
154
+ onSuccess (statusCode , headers , (JSONObject ) jsonResponse );
155
+ } else if (jsonResponse instanceof JSONArray ) {
156
+ onSuccess (statusCode , headers , (JSONArray ) jsonResponse );
157
+ } else if (jsonResponse instanceof String ) {
158
+ onSuccess (statusCode , headers , (String ) jsonResponse );
159
+ } else {
160
+ onFailure (new JSONException ("Unexpected type " + jsonResponse .getClass ().getName ()), (JSONObject ) null );
161
+ }
162
+
163
+ }
164
+ });
165
+ } catch (final JSONException ex ) {
166
+ postRunnable (new Runnable () {
167
+ @ Override
168
+ public void run () {
169
+ onFailure (ex , (JSONObject ) null );
170
+ }
171
+ });
161
172
}
162
173
}
163
174
}).start ();
@@ -168,30 +179,41 @@ public void run() {
168
179
169
180
@ Override
170
181
public void onFailure (final int statusCode , final Header [] headers , final byte [] responseBody , final Throwable e ) {
171
- new Thread (new Runnable () {
172
- @ Override
173
- public void run () {
174
- try {
175
- if (responseBody != null ) {
176
- Object jsonResponse = parseResponse (responseBody );
177
- if (jsonResponse instanceof JSONObject ) {
178
- onFailure (statusCode , headers , e , (JSONObject ) jsonResponse );
179
- } else if (jsonResponse instanceof JSONArray ) {
180
- onFailure (statusCode , headers , e , (JSONArray ) jsonResponse );
181
- } else if (jsonResponse instanceof String ) {
182
- onFailure (statusCode , headers , e , (String ) jsonResponse );
183
- } else {
184
- onFailure (new JSONException ("Unexpected type " + jsonResponse .getClass ().getName ()), (JSONObject ) null );
185
- }
186
- } else {
187
- onFailure (e , "" );
182
+ if (responseBody != null ) {
183
+ new Thread (new Runnable () {
184
+ @ Override
185
+ public void run () {
186
+ try {
187
+ final Object jsonResponse = parseResponse (responseBody );
188
+ postRunnable (new Runnable () {
189
+ @ Override
190
+ public void run () {
191
+ if (jsonResponse instanceof JSONObject ) {
192
+ onFailure (statusCode , headers , e , (JSONObject ) jsonResponse );
193
+ } else if (jsonResponse instanceof JSONArray ) {
194
+ onFailure (statusCode , headers , e , (JSONArray ) jsonResponse );
195
+ } else if (jsonResponse instanceof String ) {
196
+ onFailure (statusCode , headers , e , (String ) jsonResponse );
197
+ } else {
198
+ onFailure (new JSONException ("Unexpected type " + jsonResponse .getClass ().getName ()), (JSONObject ) null );
199
+ }
200
+ }
201
+ });
202
+
203
+ } catch (final JSONException ex ) {
204
+ postRunnable (new Runnable () {
205
+ @ Override
206
+ public void run () {
207
+ onFailure (ex , (JSONObject ) null );
208
+ }
209
+ });
210
+
188
211
}
189
- } catch (JSONException ex ) {
190
- onFailure (ex , (JSONObject ) null );
191
212
}
192
- }
193
- }).start ();
194
-
213
+ }).start ();
214
+ } else {
215
+ onFailure (e , "" );
216
+ }
195
217
}
196
218
197
219
protected Object parseResponse (byte [] responseBody ) throws JSONException {
0 commit comments