I need help with reading json file to ArrayList.
I have json file:
[
{
"name": "Wall",
"symbol": "#",
},
{
"name": "Floor",
"symbol": ".",
}
]
I have a class:
public class Tile {
public String name;
public String symbol;
}
And I have another class with 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"));
}
}
I need to fill this ArrayList with data from json file, but I have some problems. I guess the line
json.fromJson(Tile.class, Gdx.files.internal("data/tiles.json"));
is wrong.
When I try to run it there is
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: .
}
I have read the libgdx article about json files, but I found it unclear... I don't understand how to fill array. Please, help me with this case!