Retrofit 2 without Model Class

南楼画角 提交于 2019-12-31 05:31:10

问题


i want to ask about Retrofit 2.0

all this time, i knew Retrofit only with GSON Converter and get the object.

But i dont know how to get the data with API like this https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty

i'm trying to display all top stories and get the object after i load all the top stories first.

i only know with old school style like this: http://pastebin.com/JMpwjH8H


回答1:


I'm pretty sure for your example you can just set the response type as a list of Integers like this:

public interface ApiInterface {
    @GET("topstories.json?print=pretty")
    Call<List<Integer>> getTopStories();
}

Using a POJO would be too complex for what is essentially, just an array of Integers.




回答2:


First of all, you should know whether it is POST web service or GET web service. what parameters you will be giving to get the desired response and how would you store the response in POJO. This tutorial will help you with all basic thing that you require for integrating web services



来源:https://stackoverflow.com/questions/37119905/retrofit-2-without-model-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!