- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试关注 Retrofit 的 2 tutorial,但是在这部分代码中有一个 GsonConverterFactory
显示错误 Cannot resolve symbol
:
public class ServiceGenerator {
public static final String API_BASE_URL = "http://your.api-base.url";
private static OkHttpClient httpClient = new OkHttpClient();
private static Retrofit.Builder builder =
new Retrofit.Builder()
.baseUrl(API_BASE_URL)
//THIS IS THE LINE WITH ERROR!!!!!!!!!!!!
.addConverterFactory(GsonConverterFactory.create());
public static <S> S createService(Class<S> serviceClass) {
Retrofit retrofit = builder.client(httpClient).build();
return retrofit.create(serviceClass);
}
}
之前我在我的 gradle.build 中添加了,我不确定我是否应该添加 GSON,因为他们说 Retrofit 1.9 有它,但没有提到关于 Retrofit 2:
dependencies {
// Retrofit & OkHttp
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
}
最佳答案
编辑
改造 2 现已稳定。使用
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
在你的 build.gradle
依赖部分
旧答案
使用 Retrofit 2.0,您必须在 build.gradle 中声明您要使用的转换工厂。添加
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
到你的 gradle 并再次同步
关于android - Retrofit 2示例教程但GsonConverterFactory显示错误 "Cannot resolve symbol",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33304420/
如果我尝试使用 GsonConvertFactory,我会收到此错误消息: Cannot resolve Symbol GsonConverterFactory 我这样使用它: return
我已将这些依赖项包含到我的项目中: compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' compile 'com.squareup.retrofi
给出以下 JSON 响应: { "status":true, "doc":[ { "_id":"9374", "t_id
这个问题在这里已经有了答案: retrofit convertor factory can not access GsonConverterFactory (5 个答案) 关闭 7 年前。 我在设置
我正在使用返回 json 的服务器。其中一个元素要么是一个对象,要么是 false - 如果它不存在。我知道这是服务器响应的非常糟糕的实现,并且有很多这样的情况,但这就是我必须处理的。我该如何处理这种
我有一些 json,例如: { "id": 12, "title": "Title", "photo": [ "image.png" ], "o
在我的例子中,当我将子类对象放入改造请求中时,它在请求正文中变为空白 interface User{ // my super interface } class FbUser implements U
我是一名优秀的程序员,十分优秀!