JSON, Hash, not javascript

Hi,

I finally got my scene to save and load from mysql → php → javascript → unity3d (what a nightmare).

now I need to process the data I have saved and I choose to use the json format which is very webbrowser javascript friendly and easy to manage with php and very easy to save in mysql… now I have the json data sent from a html(javascript) to unity and need to process the json format in unity… and the nightmare continues here.

I stumbled upon a type called Boo.Lang.Hash and could see it would actually create key/pairs from my json format… which is almost what I wanted… of course my json format has a mix of key/pairs and arrays in it… but I expected that I could just create a new Boo.Lang.Hash for each key that was an array.

To make this more clearer, here is an example of the json I want to parse:

[
   {
      "title":"Air Landing Mat 240x400x95",
      "xp":"-16.41544",
      "yp":"3.644961E-16",
      "zp":"45.30033",
      "xr":"270",
      "yr":"90",
      "zr":"0"
   },
   {
      "title":"ProTrack M 210x1200",
      "xp":"-3.97962",
      "yp":"8.836547E-17",
      "zp":"28.33701",
      "xr":"270",
      "yr":"90",
      "zr":"0"
   }
]

I kinda expedt that I could do the following:

 for ( key in j.Keys )
	{
		var jj : Boo.Lang.Hash = eval(j[key]);
		title = jj["title"];
	}

but of course this doesn’t work… why? I have no clue… the amazing documentation about Boo.Lang.Hash and how to use it with Unity3d script is impossible to find.

can somebody help me here?

Peter

Boo.Lang.Hash is Hashtable.

–Eric

I know that… and the http://unity3d.com/support/documentation/ScriptReference/Hashtable.html

and how do I get the pair values out? only methods for “if contains”…

Peter

hmmm… it looks like I really have to create my own json parser for unity3d :frowning:

peter

Should be stored as a DictionaryEntry - so something like:

foreach(DictionaryEntry de in yourHashtable){
    Debug.Log(de.Key);
     Debug.Log(de.Value);
}

i need to get the value based on the key,. that is why j[“title”] which is pretty much a standard way in almost all other languages that have some form of dictionary.

peter

I’d recommend a Dictionary instead.