예제 #1
0
        public static void JCONTests()
        {
            var person = new Person {
                FirstName = "Jojo",
                LastName  = "Doey"
            };

            var jconString = person.ToJCON();

            Console.WriteLine($"Size of JCON {jconString.Length}");

            var jconObj = JCONConvert.DeserializeObject <Person>(jconString);

            Console.WriteLine($"FirstName: {jconObj.FirstName}");
            Console.WriteLine($"LastName: {jconObj.LastName}");

            var content = new List <Person>();

            for (var x = 0; x < 1000; x++)
            {
                content.Add(new Person {
                    FirstName = x.ToString(), LastName = (x * x).ToString()
                });
            }

            var serialized = JCONConvert.SerializeObject(content);

            Console.WriteLine($"Size of JCON {serialized.Length}");
        }
예제 #2
0
        public static void JCONvsBSONvsJSONListSizeTest()
        {
            var person = new Person {
                FirstName = "Jojo",
                LastName  = "Doey"
            };

            var tmp = new List <Person>();

            for (var x = 0; x < 100; x++)
            {
                tmp.Add(person);
            }

            var json = JsonConvert.SerializeObject(tmp);
            var jcon = JCONConvert.SerializeObject(tmp);

            Console.WriteLine($"Size of JSON {json.Length}");

            Console.WriteLine($"Size of JCON {jcon.Length}");

            using (var sw = new StreamWriter("jcon.txt")) {
                sw.Write(jcon);
            }

            var jconList = JCONConvert.DeserializeObject <List <Person> >(jcon);

            using (var sw = new StreamWriter("json.txt")) {
                foreach (var item in jconList)
                {
                    Console.WriteLine(item.FirstName + " " + item.LastName);
                }
            }
        }
예제 #3
0
        public static void InitT <T>(T objValue, string value)
        {
            var converted = JCONConvert.DeserializeObject <T>(value);

            var fields = objValue.GetType().GetRuntimeProperties().OrderBy(a => a.Name);

            foreach (var field in fields)
            {
                var val = field.GetValue(converted);

                field.SetValue(objValue, val);
            }
        }
예제 #4
0
 public void FromJCON(string value)
 {
     Copy.Init(JCONConvert.DeserializeObject <T>(value), this);
 }
예제 #5
0
 public string ToJCON(bool compress = true)
 {
     return(JCONConvert.SerializeObject(this));
 }