Skip to content Skip to sidebar Skip to footer

How To Show Toast According To The Jsonobject Response

I am doing an application in which I'm using username and password for log in, if log in is successful I'm getting user_id and all, but when invalid user try to log in, will have t

Solution 1:

JSONObject jObject;

    try {
        jObject = new JSONObject(sampledata);
        if (jObject.has("error")) {
String aJsonString = jObject.getString("error");
Toast.makeText(ActivityName.this, aJsonString, Toast.LENGTH_LONG).show();
        } else {
    Toast.makeText(ActivityName.this, "Login Successful", Toast.LENGTH_LONG).show();
        }
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

Post a Comment for "How To Show Toast According To The Jsonobject Response"