Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are two generic methods for serializing and deserializing. </p> <pre><code> /// &lt;summary&gt; /// Serializes the specified object into json notation. /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt;Type of the object to be serialized.&lt;/typeparam&gt; /// &lt;param name="obj"&gt;The object to be serialized.&lt;/param&gt; /// &lt;returns&gt;The serialized object as a json string.&lt;/returns&gt; public static string Serialize&lt;T&gt;(T obj) { Utils.ArgumentValidation.EnsureNotNull(obj, "obj"); string retVal; using (MemoryStream ms = new MemoryStream()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); serializer.WriteObject(ms, obj); retVal = Encoding.UTF8.GetString(ms.ToArray()); } return retVal; } /// &lt;summary&gt; /// Deserializes the specified json string into object of type T. /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt;Type of the object to be returned.&lt;/typeparam&gt; /// &lt;param name="json"&gt;The json string of the object.&lt;/param&gt; /// &lt;returns&gt;The deserialized object from the json string.&lt;/returns&gt; public static T Deserialize&lt;T&gt;(string json) { Utils.ArgumentValidation.EnsureNotNull(json, "json"); T obj = Activator.CreateInstance&lt;T&gt;(); using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); obj = (T)serializer.ReadObject(ms); } return obj; } </code></pre> <p>You'll need these namespaces</p> <pre><code>using System; using System.IO; using System.Runtime.Serialization.Json; using System.Text; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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