Hi
I have a JSON file i'm trying to read in. I was jumbling through it when I got completely stuck.
In the file below it's the layers bit that i'm stuck on, in it is the
tiles part and all I seem to do is read the the first element of the tiles array.
{
"level-name": "Level 1",
"tile-sizeX": 32,
"tile-sizeY": 32,
"animations": [
{"fps": 15, "is-ping-pong": false, "frames": [1, 2, 3, 4]},
{"fps": 5, "is-ping-pong": true, "frames": [6, 6, 10]}
],
"layers": [
{"sizeX": 8, "sizeY": 5, "tiles": [[5, 5, 5, 5, 5, 5, 5, 5], [5, -2, 6, 6, 6, 6, 6, 7], [5, 6, -1, 10, 10, -1, 6, 7], [5, 6, 6, 6, 6, 6, -2, 7], [5, 7, 7, 7, 7, 7, 7, 7]]},
{"sizeX": 8, "sizeY": 5, "tiles": [[7, 7, 7, 7, 7, 7, 7, 7], [7, 6, 6, 6, 6, 6, -2, 7], [7, 6, 5, -1, -1, 5, 6, 7], [7, -2, 6, 6, 6, 6, 6, 7], [7, 7, 7, 7, 7, 7, 7, 7]]}
],
"events": [
{"name": "Start", "parameters": "", "level-positions": [[2, 3], [3, 3], [4, 3], [5, 3]]},
{"name": "Finish", "parameters": "", "level-positions": [[2, 1], [3, 1], [4, 1], [5, 1]]},
{"name": "Enemy", "parameters": "VeryAngry", "level-positions": [[1, 2], [6, 2]]}
]
}
The code im using is
//layers
layers=jsonGetArray(docId,"","layers")
layerCount=jsonGetValueCount(docId,layers)
for il=0 to layerCount
layer=jsonGetArrayEntry(docId,layers,il)
sizex=jsonGetObjectValueById(docId,layer,"sizeX")
addLayer.sizeX=jsonGetValueAsInteger(docId,sizex,10)
sizey=jsonGetObjectValueById(docId,layer,"sizey")
addLayer.sizeY=jsonGetValueAsInteger(docId,sizey,10)
rowTiles=jsonGetObjectValueById(docId,layer,"tiles")
rowCount= jsonGetValueCount(docId,rowTiles)
//for ii=0 to rowCount
for i=0 to rowCount
t=jsonGetValueAsInteger(docId,jsonGetArrayEntry(docId,rowTiles,i),10)
print(t)
sync()
inc counter
next
Message(str(counter))
addLayer.tileRows.insert(addTiles)
//next
map.layers.insert(addLayer)
next
Im just not sure how to move onto the next array element or if the JSON file is not standard.
Many thanks
Scotty