Vishal Vishal - 4 months ago 15
JSON Question

How to parse login response in android?

I am confused about parsing so I want to know about how to parse. Whenever I login with valid login id and password give response

{
"data": {
"status": "1",
"Full Name": [
{
"user_id": 1,
"user_name": "deepika@soms.in",
"full_name": "",
"display_name": "",
"token": "",
"photo_url": "http://clients.vfactor.in/putt2gether/images/profile/default.jpg"
}
],
"Event": [
{
"latest_event_id": "",
"format_id": ""
}
],
"msg": "Success Login"
}
}


and if invalid login id then give response

{
"Error": {
"msg": "Please Enter valid Email Address"
}

Answer
try {
     JSONObject obj = new JSONObject(response);
            if (obj.has("Error")) {
                JSONObject objError = obj.getJSONObject("Error");
            } else if (obj.has("data")) {
                JSONObject objData = obj.getJSONObject("data");
            }
    } catch (Exception e) {
            e.printStackTrace();
    }
Comments