Пример #1
0
        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);
        }
Пример #2
0
            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);
            }
Пример #3
0
 public JsonParser(TypesInfo typesInfo)
 {
     _typesInfo = typesInfo;
 }
Пример #4
0
        public JsonObject(string source, TypesInfo typesInfo)
        {
            JsonParser parser = new JsonParser(typesInfo);

            _dict = parser.Parse(source)._dict;
        }