[Solved - Mostly] Hashtables, Arrays, Json and Slicing

So I’ve got a builtin array to store integers, its declared and initiated fine.

private var invID = new int[4]; 
invID = [0,1,2,3];

I’ve got a www call that pulls down some json information that is then parsed into a hashtable.

{    "slot1": {
		"name": "Value1",
        "id": 3
     },
	 "slot2": {
		"name": "Value2",
        "id": 2
     },
	 "slot3": {
		"name": "Value3",
        "id": 1
     },
     "slot4": {
		"name": "Value4",
        "id": 2
     }
}

var jsonHash=JSON.ParseJSON(data_get.text);

When I try to set a particular node of the integer array to a value in the hashtable I get the error.

Type 'Object' does not support slicing.

The code to set the values is as follows;

invID[0] = int.Parse(jsonHash["slot1"]["id"]);
invID[1] = int.Parse(jsonHash["slot2"]["id"]);
invID[2] = int.Parse(jsonHash["slot3"]["id"]);
invID[3] = int.Parse(jsonHash["slot4"]["id"]);

What am I missing? What exactly is slicing?

I’m not trying to set a multi-dimensional array, simply pull a data value out of it.

Do hashtables support MD? I found some examples on the unity forums that seem to show it.

Update: I don’t understand why but I think I found a workaround for this.

You have to cast the sub level hashtables again, for some reason its losing its definition from the called script.

var tempHash : Hashtable = jsonHash["slot1"];
invID[0] = int.Parse(tempHash["id"]);

Works successfully, but it kind of defeats the point if it requires all the extra code lines anyways.

I ran into the same problem trying to pass a Hashtable into a function, it seems to revert to object status anywhere outside of local context.

Looking at your code,one immediate thought is that int.Parse() is used to convert a string to an in int … however, your JSON data looks like the “id” property is already an int. It strikes me that a code fragment such as the following should be tried:

invID[0] = jsonHash["slot1"].id;