String result = “{\”error_type\”:\”success\”,\”message\”:\”Error Message…..”}”;
JSONObject json = new JSONObject(result);
if( (json.getString("error_type") == "error") {
Toast.makeText(getApplicationContext(), "Test", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Nooo", Toast.LENGTH_LONG).show();
}
This code is Toasting “Nooo”. But json.getString(“error_type”) is a “error”. What is this problem ?
You should test
Stringequality using theequalsmethod instead of==. i.e.,the
==operator compares object references and not the contents of theStringitself.