Hi,
I have a complexe Json that I managed to export by code, but now I have difficulties to import it elsewhere…
Here’s a short example of my Json:
{"sizes": [
{"1x1":[
{
"main": "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]",
"door_up": "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]"
},
{
"main": "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]",
"door_up": "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]"
}]},
{"1x2":[
{
"main": "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]",
"door_up": "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]"
}]}
]}
First thing I do to get the file is this:
levels_datas = Json.parse(File.getContent(path + file_name));
for (i in 0...levels_datas.sizes.length) {
trace(levels_datas.sizes[i]);
}
The trace is working perfectly, so no problem here, but I can’t “use” my values…
My goal here is to be able to use the imported Json datas into something like this:
private var levels:Map<String, Array<Level_Datas>> = new Map();
The keys
of the Map
would be the different sizes: 1x1, 1x2, 1x3, ...
and the value of those keys would be Array<Level_Datas>
which is every level for each size. Right now, Level_Datas
is a class that I use to manage every grid of a level that have public variables like these:
public var main:Array<Array<Int>> = new Array(); //The main grid
public var door_up:Array<Array<Int>> = new Array();
I suppose that I’ll need a typedef
, but everything I tried didn’t work…
Thank you in advance for your help!