抱歉我的英文。我尝试为android学习改造(在我使用凌空之前)。我不知道为什么它不起作用。
我的班级对象 的 PostsS
Import-Csv -Path C:\temp\serverinfo.csv |
Group-Object Servername |
ForEach-Object {if($_.count -gt 1) {$_.group | Where-Object osversion}else{$_.group} }
界面链接
private String userId;
private String id;
private String title;
private String body;
//the getters and setters
和我的主要
public interface Links {
@GET("/posts")
Call<PostsS> getPosts();
}
我有
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://jsonplaceholder.typicode.com")
.build();
Links service = retrofit.create(Links.class);
Call<PostsS> call = service.getPosts();
call.enqueue(new Callback<PostsS>() {
@Override
public void onResponse(retrofit2.Response<PostsS> response) {
Log.e("responce", response.toString());
}
@Override
public void onFailure(Throwable t) {
Log.e("error", t.toString());
}
});
我的json
Caused by: java.lang.IllegalArgumentException: Unable to create converter for class com.example.alexy.myapplication.PostsS
for method Links.getPosts
答案 0 :(得分:3)
通过改装2,您必须明确指定要使用的转换器。 E.g。
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://jsonplaceholder.typicode.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
你将Gson视为转换器吗?您还必须在build.gradle
文件中添加dependicy。 E.g。
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
尝试使用相同的-beta2
来解决与改造相关的所有问题。
修改强>
根据您发布的JSON,您的方法应该返回
Call<List<PostsS>>
代替Call<PostsS>