I got a HttpResponse which gets a json response.
Now if the json response contains data it all works fine, but whenever the json is null my application crashes.
I've been trying to following code but with no avail.
(sb = json response)
Object result11 = sb;
Log.d("Result11", result11.toString());
if (result11 == JSONObject.NULL)
Log.d("if", "I am NULL");
else
Log.d("else", "I am not null");
I tried comparing result11 to:
null, "", "null", JSONObject.NULL
It always returns "I am not null"
Whilst the log says that Resul11 = null.
Any help would be appreciated. Thanks in advance.
EDIT:
Object result11 = sb;
Log.d("Result11", result11.toString());
StringBuilder test = (StringBuilder)result11;
if (test.toString().equals("null"))
Log.d("if", "I am NULL");
else
Log.d("else", "I am not null");
SOLUTION by @Mark Byers
test.toString().trim().equals("null")
results in "I AM NULL"