json - Android Retrofit Get child object of child object -
json - Android Retrofit Get child object of child object -
i'm trying kid object data
kid object of children
if kid object of data
.
i know sound confusing, here total json object: full json
here code:
import java.util.list; import retrofit.restadapter; import retrofit.http.get; import retrofit.http.path; public class githubclient { private static final string api_url = "http://www.reddit.com/r/pcmasterrace/"; static class info { string kind; list<children> children; } static class children { info data; } interface reddit { @get("/hot.json?limit=1") list<data> data(); } public static void main() { // create simple rest adapter points github api endpoint. restadapter restadapter = new restadapter.builder() .setendpoint(api_url) .build(); // create instance of our github api interface. reddit reddit = restadapter.create(reddit.class); // fetch , print list of contributors library. list<data> info = reddit.data(); (data kid : data) { system.out.println(child.kind); } } }
i maintain getting error: java.lang.illegalstateexception: expected begin_array begin_object @ line 1 column 2
there 2 errors design in itself.
the json returned not array object trying store in list incorrect. the array called children array of info objects not array of children.datayou can handle 1 class info no point of having children class.
static class info { string kind; string modhash; info data; list<data> children; }
next accessing these values in main
public static void main(string[] args) { // create simple rest adapter points github api endpoint. restadapter restadapter = new restadapter.builder() .setendpoint(api_url) .build(); // create instance of our github api interface. reddit reddit = restadapter.create(reddit.class); // fetch , print list of contributors library. info data = reddit.data(); (data kid : data.data.children) { system.out.println(child.kind); } }
android json retrofit
Comments
Post a Comment