我是网络服务的新手,我是第一次使用 gson 库。我能够解析某些简单的 json 字符串,但我被困在这里。这是我的回应
{"message":"Action completed successfully.","results":3,"action":"param","data":[{"title":"test1","id":2,"completeCount":0},{"title":"test2","id":3,"completeCount":0},{"title":"test2","id":3,"completeCount":0}],"success":true}
这就是我试图解析它的方式
Gson gson = new Gson();
Chracter character = gson.fromJson(successResponse, Character.class);
这是我的课
public class Character {
private List<Detail> data = new ArrayList<Detail>();
private String action ;
private int results;
private String message;
private Detail detail;
public Character() {
}
public Character(List<Detail> data, String action, int results,
String message) {
super();
this.data = data;
this.action = action;
this.results = results;
this.message = message;
}
public List<Detail> getData() {
return data;
}
public void setData(List<Detail> data) {
this.data = data;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public int getResults() {
return results;
}
public void setResults(int results) {
this.results = results;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Detail getDetail() {
return detail;
}
public void setDetail(Detail detail) {
this.detail = detail;
}
public class Detail{
private String title;
private int id;
private int completeCount ;
public Detail() {
}
public Detail(String title, int id, int completeCount) {
super();
this.title = title;
this.id = id;
this.completeCount = completeCount;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getId() {
return Id;
}
public void setId(int id) {
this.id = id;
}
public int getCompleteCount() {
return completeCount;
}
public void setCompleteCount(int completeCount) {
this.completeCount = completeCount;
}
}
}