我正在尝试解析此链接 - football data org seasons
它在对象中有一些对象。对于内部对象,我创建了一个名为Season的类 -
public class Season {
private int id;
private String caption, league, year;
private int currentMatchday, numberOfMatchday, numberOfTeams, numberOfGames;
private String lastUpdated;
public Season(){
}
@Override
public String toString() {
return "Season{" +
"id=" + id +
", caption='" + caption + '\'' +
", league='" + league + '\'' +
", year='" + year + '\'' +
", currentMatchday=" + currentMatchday +
", numberOfMatchday=" + numberOfMatchday +
", numberOfTeams=" + numberOfTeams +
", numberOfGames=" + numberOfGames +
", lastUpdated='" + lastUpdated + '\'' +
'}';
}
}
这个类工作正常,因为它访问具有键,值对的内部对象链接,并且我已相应地命名了我的类字段。例如,当我访问此specific season时,我可以轻松拨打Season s = gs.fromJson(json.toString(), Season.class);
但是如何解析顶级对象(第一个链接)中的所有对象?我尝试使用ArrayList,但它给出了预期BEGIN_ARRAY但发现BEGIN_OBJECT的错误。我理解它是因为在JSON中我们有对象而不是数组。那我该怎么做呢?