public static T Deserialize <T>(string jsonString, TypesInfo typesInfo) where T : IJsonDeserializable { JsonParser parser = new JsonParser(typesInfo); T result = Activator.CreateInstance <T>(); result.FromJson(parser.Parse(jsonString)); return(result); }
public void TypeParseTest() { TypesInfo ti = new TypesInfo(); ti.RegisterType <TestClassA>(); ti.RegisterType <TestClassB>(); JsonObject jo = new JsonObject("{a:[(TestClassA){ a: 5 }, (TestClassB){ a: 5, b: 6 }]}", ti); ITestClass[] tClasses = jo.GetJsonArray("a").DeserializeToArray <ITestClass>(); Assert.AreEqual(tClasses[0].GetNum(), 5); Assert.AreEqual(tClasses[1].GetNum(), 11); }
public JsonParser(TypesInfo typesInfo) { _typesInfo = typesInfo; }
public JsonObject(string source, TypesInfo typesInfo) { JsonParser parser = new JsonParser(typesInfo); _dict = parser.Parse(source)._dict; }