嗨,有任何简单的方式使用改造与回收视图,以获取json解析器从我的在线网站。到目前为止,我使用Okhttp从本地服务器获取数据,详细的答案将是appreciated.Thanks。
发布于 2017-04-12 09:46:56
本教程肯定会帮助您将json加载到listview。
https://www.simplifiedcoding.net/retrofit-android-tutorial-to-get-json-from-server/
对于回收视图,请按以下链接操作
https://www.learn2crack.com/2016/02/recyclerview-json-parsing.html
发布于 2017-04-12 09:52:03
首先,复制API的响应并通过以下方式创建bean类
本站 *通过单击源类型到JSON *注释样式到GSON *取消标记useDoubleNumbers *取消标记AllowAdition属性
然后将这些文件复制到您的项目中。
在类中定义基本Url。
创建一个名为ApiController的接口,然后将API声明为
@FormUrlEncoded
@POST("your api link excluding the base url")
Call<Bean> callApi(@Field("your parameters") String name);然后在你的活动中写代码
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiController apiController = retrofit.create(ApiController.class);
Call<Bean> result = apiController.callApi("your parameter");
result.enqueue(new Callback<Bean>() {
@Override
public void onResponse(Call<Bean> call, Response<Bean> response) {
}
@Override
public void onFailure(Call<Bean> call, Throwable t) {
}
});发布于 2017-04-27 07:33:32
改进2.0 GET和POST方法
该链接将用于学习用于GET和POST方法的RESTFIT2.0方法。
http://www.iayon.com/consuming-rest-api-with-retrofit-2-0-in-android/
您可以在下面的链接中学习如何传递JsonArray和JsonObject
https://www.androidtutorialpoint.com/networking/retrofit-android-tutorial/
https://stackoverflow.com/questions/43365904
复制相似问题