// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Web.Script.Serialization; namespace E { public static class Json { public static object Deserialize(string json) { JavaScriptSerializer ser = new JavaScriptSerializer(); return ser.DeserializeObject(json); } } public class Program { public static void Main(string[] args) { string json = "{\"a\":\"This is a\",\"b\":{\"c\":\"This is c\",\"d\":\"This is d\"},\"e\":[1,2,3]}"; Console.WriteLine(json); IDictionary o = (IDictionary)Json.Deserialize(json); string a = (string)o["a"]; IDictionary b = (IDictionary)o["b"]; string c = (string)b["c"]; string d = (string)b["d"]; Console.WriteLine(a + " " + c + " " + d); object[] e = (object[])o["e"]; int e0 = (int)e[0]; int e1 = (int)e[1]; int e2 = (int)e[2]; Console.WriteLine(e0 + " " + e1 + " " + e2); } } }