internal static void BuildTree(object item, UniversalTreeNode node) { if (item is KeyValuePair <string, object> ) { KeyValuePair <string, object> kv = (KeyValuePair <string, object>)item; UniversalTreeNode keyValueNode = new UniversalTreeNode(); keyValueNode.Name = kv.Key; keyValueNode.Value = GetValueAsString(kv.Value); node.Children.Add(keyValueNode); BuildTree(kv.Value, keyValueNode); } else if (item is ArrayList) { ArrayList list = (ArrayList)item; int index = 0; foreach (object value in list) { UniversalTreeNode arrayItem = new UniversalTreeNode(); arrayItem.Name = $"[{index}]"; arrayItem.Value = ""; node.Children.Add(arrayItem); BuildTree(value, arrayItem); index++; } } else if (item is Dictionary <string, object> ) { Dictionary <string, object> dictionary = (Dictionary <string, object>)item; foreach (KeyValuePair <string, object> d in dictionary) { BuildTree(d, node); } } }
internal static UniversalTreeNode CreateTree(object obj) { JavaScriptSerializer jss = new JavaScriptSerializer(); var serialized = Newtonsoft.Json.JsonConvert.SerializeObject(obj); Dictionary <string, object> dic = jss.Deserialize <Dictionary <string, object> >(serialized); var root = new UniversalTreeNode(); root.Name = "Root"; BuildTree(dic, root); return(root); }