android - How to use callback for multiple json array in retrofit? -
i trying retrofit how data below response
{"schedule_students":[{"id":"753","sch_id":"153"},{"id":"765","sch_id":"153"}], "s_students":[{"id":"753","s_id":"153"},{"id":"765","s_id":"153"}], "schedu":[{"id":"753","ch_id":"153"},{"id":"765","ch_id":"153"}], "delids":"no","expdelids":"no","lastsyncdate":"2015-06-01 10:33:19"}
in api response it's having multiple json array. how retrieve data response
create pojos (plain old java objects) json data sets. use tool generate pojos.
sstudent.class
package com.example.someapp; import com.google.gson.annotations.expose; import com.google.gson.annotations.serializedname; package com.example.someapp; import com.google.gson.annotations.expose; import com.google.gson.annotations.serializedname; public class sstudent { @expose private string id; @serializedname("s_id") @expose private string sid; /** * * @return * id */ public string getid() { return id; } /** * * @param id * id */ public void setid(string id) { this.id = id; } /** * * @return * sid */ public string getsid() { return sid; } /** * * @param sid * s_id */ public void setsid(string sid) { this.sid = sid; } }
similarly, other generate other classes.
and finally,
someclass.java
package com.example.someapp; import java.util.arraylist; import java.util.list; import javax.annotation.generated; import com.google.gson.annotations.expose; import com.google.gson.annotations.serializedname; public class someclass { @serializedname("schedule_students") @expose private list<schedulestudent> schedulestudents = new arraylist<schedulestudent>(); @serializedname("s_students") @expose private list<sstudent> sstudents = new arraylist<sstudent>(); @expose private list<schedu> schedu = new arraylist<schedu>(); @expose private string delids; @expose private string expdelids; @expose private string lastsyncdate; /** * * @return * schedulestudents */ public list<schedulestudent> getschedulestudents() { return schedulestudents; } /** * * @param schedulestudents * schedule_students */ public void setschedulestudents(list<schedulestudent> schedulestudents) { this.schedulestudents = schedulestudents; } /** * * @return * sstudents */ public list<sstudent> getsstudents() { return sstudents; } /** * * @param sstudents * s_students */ public void setsstudents(list<sstudent> sstudents) { this.sstudents = sstudents; } /** * * @return * schedu */ public list<schedu> getschedu() { return schedu; } /** * * @param schedu * schedu */ public void setschedu(list<schedu> schedu) { this.schedu = schedu; } /** * * @return * delids */ public string getdelids() { return delids; } /** * * @param delids * delids */ public void setdelids(string delids) { this.delids = delids; } /** * * @return * expdelids */ public string getexpdelids() { return expdelids; } /** * * @param expdelids * expdelids */ public void setexpdelids(string expdelids) { this.expdelids = expdelids; } /** * * @return * lastsyncdate */ public string getlastsyncdate() { return lastsyncdate; } /** * * @param lastsyncdate * lastsyncdate */ public void setlastsyncdate(string lastsyncdate) { this.lastsyncdate = lastsyncdate; } }
use someclass.java in retrofit api interface this.
@get("/your_api_endpoint") someclass getsomeclass(@query("param") int param);
then access object of someclass after calling getsomeclass(param)
.
Comments
Post a Comment