我正在读取一个看起来像这样的json文件:
{
"team": [
{
"name": "Toki 1",
"id": "toki-t1-s1",
"compatibility": {
"score": 20.0,
"comment": "From 'Team1 Toki1' to 'Team1 Toki1'\n'done!'"
}
}
],
"extra_comments": "That's all! It was 'fun'! (said Team1 Toki1)"
}
这是我的代码:
Gson gson = new Gson();
JsonReader reader = new JsonReader(new FileReader("one.json"));
Toki toki = gson.fromJson(reader, Toki.class);
这是Toki课:
public class Toki {
private String extra_comments;
private Team[] team;
public String getExtra_comments() {
return extra_comments;
}
public Team[] getTeam() {
return team;
}
}
团队班级:
public class Team {
private String name;
private String id;
private Compatibility compatibility;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Compatibility getCompatibility() {
return compatibility;
}
public void setCompatibility(Compatibility compatibility) {
this.compatibility = compatibility;
}
}
兼容性类:
public class Compatibility {
private String comment;
private double score;
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
我的问题是我可以通过执行以下操作来打印extra_comments: Toki toki =新的Toki(); System.out.print(toki.getExtra_comments());
但是当我对团队数组执行相同操作时,它返回[LTeam; @ 6321e813,而不是实际的团队。有人知道为什么吗?