关于android使用retrofit2 demo遇到的问题
来源:互联网 发布:异步加载js的方法 编辑:程序博客网 时间:2024/04/30 17:42
public final class SimpleService { public static final String API_URL = "https://api.github.com"; public static class Contributor { public final String login; public final int contributions; public Contributor(String login, int contributions) { this.login= login; this.contributions= contributions; } } public interface GitHub { @GET("/repos/{owner}/{repo}/contributors") Call<List<Contributor>>contributors( @Path("owner")String owner, @Path("repo")String repo); } public static void main(String... args) throws IOException { // Create a very simple REST adapter which points the GitHub API. Retrofit retrofit = new Retrofit.Builder() .baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); // Create an instance of our GitHub API interface. GitHub github = retrofit.create(GitHub.class); // Create a call instance for looking up Retrofit contributors. Call<List<Contributor>> call= github.contributors("square","retrofit"); // Fetch and print a list of the contributors to the library. List<Contributor> contributors= call.execute().body(); for (Contributor contributor: contributors) { System.out.println(contributor.login+ " ("+ contributor.contributions+ ")"); } } }
把代码转移到android项目中去,GsonConverterFactory会找不到。
compile 'com.squareup.retrofit2:retrofit:2.0.1'
在导入这个的基础上需要再导入一个
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
0 0
- 关于android使用retrofit2 demo遇到的问题
- android 关于使用retrofit2.0的一些问题
- Android Retrofit2的使用
- Android 使用Retrofit2问题汇总
- rxjava2 + retrofit2 + okhttp3遇到的问题
- Android 关于使用阿里Freeline遇到的问题
- 关于Android Studio使用SVN遇到的一些问题
- Retrofit2.0+okhttp3缓存机制以及遇到的问题
- retrofit2+okhttp3+ rxjava 遇到的问题及解决方案
- Retrofit2.0+okhttp3缓存机制以及遇到的问题
- Android 使用MVP Rxjava2+Retrofit2+Dagger2写的一个登录注册(含后台+数据库)的demo
- Android学习笔记之Retrofit2的使用
- android retrofit2.0框架的使用介绍
- 关于 SHFILEOPSTRUCT 的使用遇到的问题
- 关于sublime 使用的遇到的问题
- 关于Android Socket编程遇到的问题
- android关于用真机测试遇到的问题
- 关于android环境搭建遇到的问题
- BZOJ2465: [中山市选2009]小球
- TransE论文:多元关系数据嵌入
- 2016第七届蓝桥杯--剪邮票(DFS)
- 跟我总结OAuth2.0
- 圆形头像
- 关于android使用retrofit2 demo遇到的问题
- 2014年王道论坛计算机考研机试全真模拟考试
- BZOJ2631: tree link-cut-tree
- Android的AndroidManifest.xml android:process元素说明
- referer问题
- Jeesite工作流程
- bzoj 3600: 没有人的算术 替罪羊树
- 上传图片js判断
- 从头认识多线程-1.4 isAlive()和Sleep()