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}"); }
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); } } }
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); } }
public void FromJCON(string value) { Copy.Init(JCONConvert.DeserializeObject <T>(value), this); }
public string ToJCON(bool compress = true) { return(JCONConvert.SerializeObject(this)); }