注释唯一的问题是
public class Game { private int id; @XmlElement(name = "GameTitle") //You need to add this since first letter is uppercase, otherwise the GameTitle will not unmarshall. private String gameTitle; ... your pre ...}那么为什么其余的都不起作用呢?
服务器返回URL的HTTP响应代码:403:http :
//thegamesdb.net/api/GetGame.php?id=2
403 =禁止
解决方案 (使服务器相信您是浏览器)
URL url = new URL("http://thegamesdb.net/api/GetGame.php?id=2");HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.addRequestProperty("User-Agent", "Mozilla/4.76"); InputStream is = http.getInputStream();Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();customer = (Data) jaxbUnmarshaller.unmarshal(is);List<Game> games = customer.getGames();game = games.get(0);注意:
Try catch final,关闭流并检查
NullPointer是否超出本示例的范围,取决于用户。



