Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another option is to serialize to json. <strike>I do not know about performance, but</strike> I just compared the output when serializing a fairly complex list of entities to json vs. xml, and json is much more compact. Using json the resulting string was 1301303 bytes. With xml, 2429630. So it's almost half the size using json. </p> <p>Below is the helper class I use when serializing/deserializing to json.</p> <p><strong>EDIT</strong><br> I did some performance testing, and it actually turns out that json is faster as well. With xml, serializing 10000 objects took 636 milliseconds, with json only 257. Does anybody know if there are reasons not to choose json over xml?</p> <p><strong>EDIT</strong><br> Tested again, with real data this time:<br> (1000 objects)<br> Uncompressed json: 605 kb<br> Uncompressed xml: 3,53 MB (!)<br> Zipped json: 28,5 kb<br> Zipped xml: 69,9 kb<br> Performance when using pre-initialized serializer:<br> json: ~350 ms<br> xml: ~120 ms </p> <pre><code>using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.IO; using System.Text; using System.Runtime.Serialization.Json; namespace GLS.Gui.Helper { public static class SerializationHelper { public static string SerializeToJsonString(object objectToSerialize) { using (MemoryStream ms = new MemoryStream()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(objectToSerialize.GetType()); serializer.WriteObject(ms, objectToSerialize); ms.Position = 0; using (StreamReader reader = new StreamReader(ms)) { return reader.ReadToEnd(); } } } public static T Deserialize&lt;T&gt;(string jsonString) { using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T)); return (T)serializer.ReadObject(ms); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload