I am developing a small side scroller game using slick 2D lwjgl and am running into a current error while casting something.
It seems to be not recognizing that i'm casting the json string as a JsonArray.
The error and the function,
java.lang.ClassCastException: java.lang.String cannot be cast to org.json.simple.JSONArray
at world.World.load(World.java:35)
at game.Engine.initStatesList(Engine.java:64)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:164)
function:
public static void load(String path) throws Exception
{
JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader(path));
JSONObject jSonOBJ = (JSONObject)obj;
JSONArray layers = (JSONArray)jSonOBJ.get("layers");
int amount = layers.size();
for (int i = 0; i < amount; ++i)
{
JSONObject layer = (JSONObject) layers.get(i);
String type = (String)layer.get("name");
if (type.equals("solids"))
{
solids = parse((JSONArray)layer.get("data")); //error
}
else if (type.equals("spawns"))
{
//to-do
}
}
}
this is just to parse if the json, my map, tile is a solid or not, but I have been stuck on this small error for a little time. the line of code solids = parse((JSONArray)layer.get("data"));
should convert it to JSONArray correct?