我正在尝试将对象转换为列表,但我不知道该怎么做。该对象是从改造调用到服务器的回调。我真的可以帮忙
我的改造电话是
@POST("{path}")
Call<Object> getPasswords(@Body Map<String, String> object, @Path("path") String path);
以及onResponse返回的内容:
{
"0":{
"label":"Facebook","id":"246","Facebook":"Yes","date":"March-01-2018"
},
"1":{
"label":"webby","id":"247","webby":"Yes","date":"March-01-2018"
}
}
我正在尝试将信息传递给Java模型并将其添加到列表项 她是我的Java模型
public class Passwords {
private Integer id;
private String label;
private String user;
private String password;
private String sq1;
private String sq2;
private String sq3;
private String locked;
private String date;
public Passwords(String label, String user, String password, String sq1, String sq2, String sq3, String locked, String date) {
this.label = label;
this.user = user;
this.password = password;
this.sq1 = sq1;
this.sq2 = sq2;
this.sq3 = sq3;
this.locked = locked;
this.date = date;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSq1() {
return sq1;
}
public void setSq1(String sq1) {
this.sq1 = sq1;
}
public String getSq2() {
return sq2;
}
public void setSq2(String sq2) {
this.sq2 = sq2;
}
public String getSq3() {
return sq3;
}
public void setSq3(String sq3) {
this.sq3 = sq3;
}
public String getLocked() {
return locked;
}
public void setLocked(String locked) {
this.locked = locked;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
这是我感到困惑的地方,我不知道如何创建要与gson传递给我的列表项,这不起作用
@Override
public void onResponse(Call<Object> call, Response<Object> response) {
Object object = response.body();
Type listType = new TypeToken<List<Passwords>>() {}.getType();
List<Passwords> yourList = new Gson().fromJson(object.toString(), listType);
}