android - In Retrofit in API call Success Gives User Object And Failure Does Not Gives User Object Then How to check that in Retrofit Success Block? -
user success login response
{ "user": [ { "name": " xyz", "email": "zy@gmail.com", "address": " ahmedabad, gujarat, india", "profilepic": "../media/profilepic/xyz_n6gsitknom_11apr16_11421442.png", "qrcode": "1", "devicetype": "1", "devicetoken": "(null)", "deviceid": "", "paymentflag": "0", "photographerflag": "0", "phone": "123456", "weburl": "", "type": "photographer", "validate": "online", "professional": "1", "events": "1.events(wedding,birthday,parties,etc)", "photoshoot": "2.portrait photoshoot(outdoor,indoor)", "realestate": "3.real estate", "baby": "0", "invite_code": "", "aphotpassid": [ "" ]`enter code here` } ] }
user failure response
{"message":"fail"}
then how message object called in retrofit
retrofit android java file
@override public void success(object o, response response) { messageutil.hideprogressdialog(); user object = (user) o; if (object.equals("fail")) { messageutil.showmessagedialog("server error !!"); } else { startactivity(new intent(loginactivity.this, homeactivity.class)); } } @override public void failure(retrofiterror error) { messageutil.hideprogressdialog(); messageutil.showmessagedialog("server error !!"); }
how can called message object in android? can possible when failure response without object in android success response ? can possible minor changes , problem solved >
thanks
try in onsuccess() code:
@override public void success(object o, response response) { messageutil.hideprogressdialog(); try{ jsonobject jsonobject = new jsonobject(response.tostring()) if(jsonobject.has("user")){ startactivity(new intent(loginactivity.this, homeactivity.class)); } else{ messageutil.showmessagedialog("server error !!"); } } catch(exception e){ } }
Comments
Post a Comment