我需要帮助读取json文件到ArrayList.
我有json文件:
[ { "name": "Wall","symbol": "#",},{ "name": "Floor","symbol": ".",} ]
我有一个班:
public class Tile { public String name; public String symbol; }
我有另一个类与ArrayList:
public class Data { public static ArrayList<Tile> tilesData; public static void loadData() { tilesData = new ArrayList<Tile>(); Json json = new Json(); json.fromJson(Tile.class,Gdx.files.internal("data/tiles.json")); } }
我需要使用json文件中的数据填充这个ArrayList,但是我有一些问题.我猜线
json.fromJson(Tile.class,Gdx.files.internal("data/tiles.json"));
是错的.
当我尝试运行它
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: data/tiles.json Caused by: com.badlogic.gdx.utils.SerializationException: Unable to convert value to required type: [ { name: Wall,symbol: # },{ name: Floor,symbol: . }