java - How to Access Child Item In JSON Array -


i querying flickr based on search terms, , response json array. here root level along first 2 results:

{  photos: {    page: 1,    pages: 4222,    perpage: 100,    total: "422175",       photo: [           {           id: "28571356563",           owner: "8372889@n03",secret: "c4ca6c4364",           server: "8050",           farm: 9,           title: "95040021.jpg",           ispublic: 1,           isfriend: 0,           isfamily: 0,           url_m: "https://farm9.staticflickr.com/8050/28571356563_c4ca6c4364.jpg",           height_m: "332",           width_m: "500"                },           {           id: "28571342883",           owner: "96125450@n00",           secret: "db35a59412",           server: "8307",           farm: 9,           title: "red #sunset #silhouette #trees #photography",           ispublic: 1,           isfriend: 0,           isfamily: 0,           url_m: "https://farm9.staticflickr.com/8307/28571342883_db35a59412.jpg",           height_m: "500",           width_m: "424"             }, 

when load results, going iterate through items (the "total" figure) , load recyclerview.

ultimately, want iterate through "photos" , "url_m" each photo. here current call flickr api through retrofit:

 call<list<photo>> call = apiinterface.getimages(mquery);             call.enqueue(new callback<list<photo>>() {                 @override                 public void onresponse(call<list<photo>> call, response<list<photo>> response) {                  }                  @override                 public void onfailure(call<list<photo>> call, throwable t) {                  }             });          }     }); 

how iterate through photos , url each photo? have model classes set each map flickr api json objects:

i think you're implementing wrong retrofit callback in code. can see you're receiving first jsonobject called photos contains jsonarray photo, code should this

call<photoresult> call = apiinterface.getimages(query); call.enqueue(new callback<photoresult>() {...} 

as can see, callback object photoresult root level of json response, , inside should retrieve list<photo> collection.

to generate pojos can use website http://www.jsonschema2pojo.org/

your pojos should this

public class photoresult {     @serializedname("photos")     @expose     public photos photos; }  public class photos {     @serializedname("page")     @expose     public integer page;     @serializedname("pages")     @expose     public integer pages;     @serializedname("perpage")     @expose     public integer perpage;     @serializedname("total")     @expose     public string total;     @serializedname("photo")     @expose     public list<photo> photo = new arraylist<photo>(); }  public class photo {     ... }  

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -