@@ -122,16 +122,17 @@ public void run() {
122
122
postRunnable (new Runnable () {
123
123
@ Override
124
124
public void run () {
125
- if (jsonResponse instanceof JSONObject ) {
125
+ if (jsonResponse == null ){
126
+ onSuccess (statusCode , headers , (String ) jsonResponse );
127
+ }else if (jsonResponse instanceof JSONObject ) {
126
128
onSuccess (statusCode , headers , (JSONObject ) jsonResponse );
127
129
} else if (jsonResponse instanceof JSONArray ) {
128
130
onSuccess (statusCode , headers , (JSONArray ) jsonResponse );
129
131
} else if (jsonResponse instanceof String ) {
130
- onFailure (statusCode , headers , (String ) jsonResponse , new JSONException ( "Response cannot be parsed as JSON data" ) );
132
+ onSuccess (statusCode , headers , (String ) jsonResponse );
131
133
} else {
132
134
onFailure (statusCode , headers , new JSONException ("Unexpected response type " + jsonResponse .getClass ().getName ()), (JSONObject ) null );
133
135
}
134
-
135
136
}
136
137
});
137
138
} catch (final JSONException ex ) {
@@ -166,7 +167,9 @@ public void run() {
166
167
postRunnable (new Runnable () {
167
168
@ Override
168
169
public void run () {
169
- if (jsonResponse instanceof JSONObject ) {
170
+ if (jsonResponse == null ){
171
+ onFailure (statusCode , headers , (String ) jsonResponse , throwable );
172
+ }else if (jsonResponse instanceof JSONObject ) {
170
173
onFailure (statusCode , headers , throwable , (JSONObject ) jsonResponse );
171
174
} else if (jsonResponse instanceof JSONArray ) {
172
175
onFailure (statusCode , headers , throwable , (JSONArray ) jsonResponse );
@@ -220,13 +223,20 @@ protected Object parseResponse(byte[] responseBody) throws JSONException {
220
223
if (jsonString .startsWith (UTF8_BOM )) {
221
224
jsonString = jsonString .substring (1 );
222
225
}
223
- if (jsonString .startsWith ("{" ) || jsonString .startsWith ("[" )) {
226
+ // Check if the string is an JSONObject style {} or JSONArray style []
227
+ // If not we consider this as a string
228
+ if (( jsonString .startsWith ("{" ) && jsonString .endsWith ("}" ) )
229
+ || jsonString .startsWith ("[" ) && jsonString .endsWith ("]" ) ) {
224
230
result = new JSONTokener (jsonString ).nextValue ();
231
+ return result ;
232
+ }
233
+ // Check if this is a String "my String value" and remove quote
234
+ // Other value type (numerical, boolean) should be without quote
235
+ else if ( jsonString .startsWith ("\" " ) && jsonString .endsWith ("\" " ) ){
236
+ result = jsonString .substring (1 ,jsonString .length ()-1 );
237
+ return result ;
225
238
}
226
239
}
227
- if (result == null ) {
228
- result = jsonString ;
229
- }
230
- return result ;
240
+ return jsonString ;
231
241
}
232
242
}
0 commit comments