Is there a nicer way to do this?
JavaScriptSerializer jss = new JavaScriptSerializer();
Dictionary<string, object> dic =
jss.Deserialize<Dictionary<string, object>>(json);
Dictionary<string, object>.Enumerator enumerator = dic.GetEnumerator();
enumerator.MoveNext();
ArrayList arr = (ArrayList)enumerator.Current.Value;
foreach (Dictionary<string, object> item in arr)
{
string compID = item["compID"].ToString();
string compType = item["compType"].ToString();
}
All I want is my array of items (i.e. comp)
I am sending a json like this:
{ "comps" : [ { compID : 1 , compType : "t" } , { ect. } ] }
Yes, by defining models:
and then deserialize the JSON string to this model so that you can work with strong types, not some dictionaries of magic strings: