我正在制作一个用于教育目的的简单 RetroFit 应用程序,并使用 IntelliJ IDEA 作为我的 IDE。
我已经正确导入了 Retrofit 库(至少我认为我已经导入了),但我无法获取 Gson Converter 包。我安装了来自 google 的 gson.jar,但在这两个库中都没有一个名为“GsonConverterFactory”的类,这是我解析 JSON 所必需的。
编辑:我在 Windows 上。
Add compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
给你的build.gradle
文件并解决依赖关系或将相应的 jar 添加到您的 bulid 路径中。
然后使用GsonConverterFactory.create()
得到Converter Factory
我尝试使用2.0.0-beta1
但它给了我工厂的非法类型转换错误,如下所示,因此移至2.0.0-beta2
error: method addConverterFactory in class Builder cannot be applied to given types;
required: Factory
found: GsonConverterFactory
reason: actual argument GsonConverterFactory cannot be converted to Factory by method invocation conversion
所以我的建议是使用2.0.0-beta2
我的 build.gradle 有以下依赖项来解决改造问题。
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)