Android Retrofit使用(一)
来源:互联网 发布:云南广电网络oa 编辑:程序博客网 时间:2024/05/02 21:10
最近在网上看到一些比较不错的东西,在这里记录学习下。这里将讲到Android Retrofit的使用。
首先,导包:retrofit开发要用到的包
下载copy至项目libs下,添加依赖就ok了。
开发小实例:
访问此链接会得到json:https://api.github.com/repos/square/retrofit/contributors
接下来的实例就是访问该网址解析json获得java对象
首先,定义接口,也就是定义访问的网址和访问方式:
public interface Login{ @GET("/repos/{owner}/{repo}/contributors") Call<List<Contributor>> getConContributor(@Path("owner") String owner, @Path("repo") String repo); }
解释:@GET("/repos/{owner}/{repo}/contributors")
这里是注解的方式,通过get方式请求网络,{ }中间的值就是get方式要传入的值
重新开启线程请求网络
private void SimpleThread(){ Thread thread = new Thread(){ @Override public void run() { super.run(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.github.com") .addConverterFactory(GsonConverterFactory.create()) .build(); Login login = retrofit.create(Login.class); Call<List<Contributor>> call=login.getConContributor("square", "retrofit"); try { List<Contributor> list=call.execute().body(); Log.i("----",""+list.size()); } catch (IOException e) { e.printStackTrace(); } } }; thread.start(); }
权限:
<uses-permission android:name="android.permission.INTERNET"/>
以上就是最基本的retrofit使用方法。更多方式:更多请求方式
0 0
- Android Retrofit使用(一)
- Android Retrofit使用教程(一)
- Android retrofit历程(一)
- android retrofit 示例(一)
- Retrofit使用教程(一)- Retrofit入门详解
- Retrofit使用教程(一)- Retrofit入门详解
- Android框架学习之Retrofit(一)
- Android Retrofit 2.0(一)初识介绍
- Retrofit的使用详解(一)
- Retrofit的简单使用(一)
- Retrofit使用教程(一)
- Retrofit 使用 一
- Retrofit使用教程(一)
- Retrofit使用教程(一)
- Retrofit的使用【一】
- Retrofit使用一
- Android - Retrofit 基础使用
- Android Retrofit 2.0使用
- 数据结构笔记--haffman树与haffman编码分析
- Git用户手册--Git 内部原理
- 经典排序算法3:堆排序
- java-并发-ConcurrentHashMap高并发机制-jdk1.8
- 实现QQ空间中显示照片效果
- Android Retrofit使用(一)
- Spoon Devil Love Arithmetic
- C++基础:文件与对象
- HDU - 5319 Painter
- POJ1328-Radar Installation(贪心)
- POJ 1860 Currency Exchange
- HDU 1598 find the most comfortable road
- 对最小二乘法的概率解释.
- C++重载函数的实现小结(实战篇)