Reading Multidimensional Data I've Already Loaded

Hello,

I’m importing data via JSONParse. The data imports fine. I’m having a problem accessing it.

How do I reference a multidimensional array/object once the data has been loaded?

For example this code works:

levelDataRaw = Resources.Load("Levels") as TextAsset;
levelData = JSONParse.JSONParse(levelDataRaw.ToString()) as Hashtable;
	
for (var level : Hashtable in levelData['levels'])
{
    	print(level["data"]);
}

but when I try to access anything beneath data like this, it does not:

print(level["data"]["blocks"]);

This throws the following error: Type object does not support slicing.

This is the JSON data that appears to be loading in fine:

{
	"levels" : [
		{
			"number" : 1,
			"name" : "Level 1",
			"width" : 10,
			"height" : 8,
			"author" : "Tester",
			"data" : 
				{
					"blocks" : [
						{
							"x" : 2,
							"y" : 1
						},
						{
							"x" : 3,
							"y" : 1
						}
					]
				}
		}
	]
}

Do you have #pragma strict in your script? For this particular script, it might be worthwhile to remove it (carefully! :)) if you know what you’re doing.

level[“data”] returns an object. Hashtables have no idea what data they contain, so they -have- to return objects.

Objects don’t have a " " function (“slicing” function). But YOU know it’s a Hashtable, so you can do this:

(level[“data”] as Hashtable)[“blocks”]

That says “treat the value in level[“data”] as a Hashtable, then perform a slice on it”.

Science!

Thanks for the help. I appreciate it.