0
我發現這個錯誤很多主題,但我沒有找到任何解決方案... 希望你們其中一個可以幫我解決這個問題。
我有一個問題,從文本文件解析一個JSON到一個Java對象。
我讀的文件,我想將它們轉換爲使這裏的對象是代碼:
private ArrayList<Game> gameList;
for (File file : gamesFolder.listFiles()) {
BufferedReader br = new BufferedReader(new FileReader(file));
//Line below is where it crash
Game game = new Gson().fromJson(br, Game.class);
this.gameList.add(game);
}
我的遊戲類:
public class Game {
private Integer id;
private String game;
private List<String> items;
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public String getGame() { return game; }
public void setGame(String game) { this.game = game; }
public List<String> getItems() { return items; }
public void setItems(List<String> items) { this.items = items; }
}
最後的json:
{
"id": 730,
"game": "Counter-Strike: Global Offencive",
"items": [
"Clé de caisse spectrale",
"Caisse spectrale",
"AWP | Asiimov"
]
}
感謝您的幫助!
調試此代碼,但確保'文件'實際上是包含上述json的文件 - 添加'System.out.println(文件);' –
是的文件是好的,我實例化gamelist在我的構造器中,但我沒有看到它 – tontonfranki