我正在尝试从这个网站显示游戏的标题和ID:http://thegamesdb.net/api/GetGame.php?id = 2
当我从这个网址解组时:http://www.w3schools.com/xml/note.xml一切都好,但这里只有一个对象,而不是列表.所以我现在遇到问题.我正在阅读谷歌的一些教程和示例,我制作了这段代码:
Data.java:
@XmlRootElement( name = "Data" )
@XmlAccessorType (XmlAccessType.FIELD)
public class Data {
@XmlElement(name = "Game")
List<Game> games;
public List<Game> getGames() {
return games;
}
public void setGames(List<Game> games) {
this.games = games;
}
}
Run Code Online (Sandbox Code Playgroud)
Game.java文件:
@XmlRootElement(name = "Game")
@XmlAccessorType (XmlAccessType.FIELD)
public class Game {
private int id;
private String gameTitle;
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getGameTitle(){
return gameTitle;
} …Run Code Online (Sandbox Code Playgroud)