Skip to content

Commit 9272f3e

Browse files
committed
Merge pull request android-async-http#93 from sillydong/master
Fix a NullPointerException in JsonHttpResponseHandler if response is not json type
2 parents eccbce2 + 425b2d4 commit 9272f3e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/com/loopj/android/http/JsonHttpResponseHandler.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ protected void handleSuccessJsonMessage(Object jsonResponse) {
108108
protected Object parseResponse(String responseBody) throws JSONException {
109109
Object result = null;
110110
//trim the string to prevent start with blank, and test if the string is valid JSON, because the parser don't do this :(. If Json is not valid this will return null
111-
responseBody = responseBody.trim();
112-
if(responseBody.startsWith("{") || responseBody.startsWith("[")) {
113-
result = new JSONTokener(responseBody).nextValue();
114-
}
115-
return result;
111+
responseBody = responseBody.trim();
112+
if(responseBody.startsWith("{") || responseBody.startsWith("[")) {
113+
result = new JSONTokener(responseBody).nextValue();
114+
}
115+
if (result == null) {
116+
result = responseBody;
117+
}
118+
return result;
116119
}
117120

118121
@Override

0 commit comments

Comments
 (0)