Esempio n. 1
0
        public static void ParseArray2()
        {
            List <object> array = JsonParser.ParseValue(@"[[0, 1], [true, false], [""a"", ""b"", ""c""]]") as List <object>;

            Assert.IsNotNull(array);

            List <object> sub1 = array[0] as List <object>;

            Assert.IsNotNull(sub1);
            Assert.AreEqual(0, sub1[0]);
            Assert.AreEqual(1, sub1[1]);

            List <object> sub2 = array[1] as List <object>;

            Assert.IsNotNull(sub2);
            Assert.AreEqual(true, sub2[0]);
            Assert.AreEqual(false, sub2[1]);

            List <object> sub3 = array[2] as List <object>;

            Assert.IsNotNull(sub2);
            Assert.AreEqual("a", sub3[0]);
            Assert.AreEqual("b", sub3[1]);
            Assert.AreEqual("c", sub3[2]);
        }
Esempio n. 2
0
        public static void ParseObject2()
        {
            Dictionary <string, object> obj = JsonParser.ParseValue(@"{""a"" : {}, ""b"" : null, ""c"":[]}") as Dictionary <string, object>;

            Assert.IsNotNull(obj);

            Assert.AreEqual(new Dictionary <string, object>(), obj["a"]);
            Assert.AreEqual(null, obj["b"]);
            Assert.AreEqual(new List <object>(), obj["c"]);
        }
Esempio n. 3
0
        public static void ParseObject1()
        {
            Dictionary <string, object> obj = JsonParser.ParseValue(@"{""a"":1, ""b"":null, ""c"":0.3}") as Dictionary <string, object>;

            Assert.IsNotNull(obj);

            Assert.AreEqual(1, obj["a"]);
            Assert.AreEqual(null, obj["b"]);
            Assert.AreEqual(0.3, obj["c"]);
        }
Esempio n. 4
0
        public static T Decode <T>(this string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(default(T));
            }
            object jsonObj = JsonParser.ParseValue(json);

            if (jsonObj == null)
            {
                return(default(T));
            }
            return(JsonMapper.DecodeJsonObject <T>(jsonObj));
        }
Esempio n. 5
0
        public static object Decode(this string json, Type type)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }
            object jsonObj = JsonParser.ParseValue(json);

            if (jsonObj == null)
            {
                return(null);
            }
            return(JsonMapper.DecodeJsonObject(jsonObj, type));
        }
Esempio n. 6
0
        public static void ParseArray1()
        {
            List <object> array = JsonParser.ParseValue(@" [0, 1, 2.2, true, false, null, ""test""] ") as List <object>;

            Assert.IsNotNull(array);

            Assert.AreEqual(0, array[0]);
            Assert.AreEqual(1, array[1]);
            Assert.AreEqual(2.2, array[2]);
            Assert.AreEqual(true, array[3]);
            Assert.AreEqual(false, array[4]);
            Assert.AreEqual(null, array[5]);
            Assert.AreEqual("test", array[6]);
        }
 public static object ParseValue(string jsonString)
 {
     using (var parser = new JsonParser(jsonString)) {
         return(parser.ParseValue());
     }
 }
Esempio n. 8
0
 public static object ParseValue(string jsonString)
 {
     using (var instance = new JsonParser(jsonString)) {
         return instance.ParseValue();
     }
 }
Esempio n. 9
0
        public static void ParseString1()
        {
            string str = JsonParser.ParseValue("\"test\"") as string;

            Assert.AreEqual("test", str);
        }
Esempio n. 10
0
        public static void ParseString4()
        {
            string str = JsonParser.ParseValue("Test\"") as string;

            Assert.IsNull(str);
        }
Esempio n. 11
0
        public static void ParseString2()
        {
            string str = JsonParser.ParseValue(" \" \\\"Test\\\" \" ") as string;

            Assert.AreEqual(" \"Test\" ", str);
        }
Esempio n. 12
0
        public static void ParseUTF8String1()
        {
            string str = JsonParser.ParseValue("\"\\u20AC \\u00F6 \\u00DC \\u00E9\"") as string;

            Assert.AreEqual("€ ö Ü é", str);
        }