How to use json response in gson library + android + java -
How to use json response in gson library + android + java -
i getting web service response this.i getting response here .
@override public void getwebserviceresponse(string result) { // todo auto-generated method stub log.d("-----", "naveen"+ result); }
now need utilize gson library create model or dot , holder class
holder:
public class holder { list<deparaturedaseboarddto> data; } **dto:**
package com.firstgroup.dto;
public class deparaturedaseboarddto { @serializedname("alertsid") int alertsid; @serializedname("destexparrival") string destexparrival; @serializedname("destscharrival") string destscharrival; @serializedname("expdepart") string expdepart; @serializedname("filteredstation") string filteredstation; @serializedname("platformno") string platformno; @serializedname("rid") string rid; @serializedname("schdepart") string schdepart; @serializedname("toc") string toc; @serializedname("toexparrival") string toexparrival; @serializedname("toscharrival") string toscharrival; @serializedname("trainid") string trainid; @serializedname("trainlastreportedat") string trainlastreportedat; @serializedname("destinationstation") destinationstation destinationstation; public deparaturedaseboarddto(string trainid,string toc,string trainlastreportedat, string platformno, string schdepart, string expdepart, int alertsid, string rid, string destscharrival, string filteredstation, string destexparrival, string toscharrival, string toexparrival,destinationstation destinationstation){ this.trainid=trainid; this.toc=toc; this.trainlastreportedat=trainlastreportedat; this.platformno=platformno; this.schdepart=schdepart; this.expdepart=expdepart; this.alertsid=alertsid; this.destinationstation=destinationstation; this.toexparrival=toexparrival; this.toscharrival=toscharrival; this.destexparrival=destexparrival; this.filteredstation=filteredstation; this.destscharrival=destscharrival; this.rid=rid; } public destinationstation getdestinationstation() { homecoming destinationstation; } public void setdestinationstation(destinationstation destinationstation) { this.destinationstation = destinationstation; } public int getalertsid() { homecoming alertsid; } public void setalertsid(int alertsid) { this.alertsid = alertsid; } public string getdestexparrival() { homecoming destexparrival; } public void setdestexparrival(string destexparrival) { this.destexparrival = destexparrival; } public string getdestscharrival() { homecoming destscharrival; } public void setdestscharrival(string destscharrival) { this.destscharrival = destscharrival; } public string getexpdepart() { homecoming expdepart; } public void setexpdepart(string expdepart) { this.expdepart = expdepart; } public string getfilteredstation() { homecoming filteredstation; } public void setfilteredstation(string filteredstation) { this.filteredstation = filteredstation; } public string getplatformno() { homecoming platformno; } public void setplatformno(string platformno) { this.platformno = platformno; } public string getrid() { homecoming rid; } public void setrid(string rid) { this.rid = rid; } public string getschdepart() { homecoming schdepart; } public void setschdepart(string schdepart) { this.schdepart = schdepart; } public string gettoc() { homecoming toc; } public void settoc(string toc) { this.toc = toc; } public string gettoexparrival() { homecoming toexparrival; } public void settoexparrival(string toexparrival) { this.toexparrival = toexparrival; } public string gettoscharrival() { homecoming toscharrival; } public void settoscharrival(string toscharrival) { this.toscharrival = toscharrival; } public string gettrainid() { homecoming trainid; } public void settrainid(string trainid) { this.trainid = trainid; } public string gettrainlastreportedat() { homecoming trainlastreportedat; } public void settrainlastreportedat(string trainlastreportedat) { this.trainlastreportedat = trainlastreportedat; } }
response
{ "data": [ { "trainid": "2a04", "toc": "se", "trainlastreportedat": null, "platformno": "2 ", "destinationstation": { "crscode": "vic", "stationname": "london victoria" }, "schdepart": "06:43", "expdepart": "06:43", "alertsid": 0, "rid": "201410231556369", "destscharrival": "06:53", "destexparrival": "06:53", "filteredstation": null, "toscharrival": null, "toexparrival": null }, { "trainid": "2o00", "toc": "tl", "trainlastreportedat": null, "platformno": "1 ", "destinationstation": { "crscode": "lut", "stationname": "luton" }, "schdepart": "06:46", "expdepart": "06:46", "alertsid": 0, "rid": "201410231543833", "destscharrival": "07:53", "destexparrival": "07:53", "filteredstation": null, "toscharrival": null, "toexparrival": null } ], "alertdetailpopulated": false, "success": true, "alertdata": null }
how objects of web service in holder object using gson
you can seek utilize fromjson() gson
this example
@override public void getwebserviceresponse(string result) { log.d("-----", "naveen"+ result); holder info = new gson().fromjson(result, holder.class); }
java android gson
Comments
Post a Comment