Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to use DataContractJsonSerializer which is in the System.Runtime.Serialization.Json namespace. Mark your class with the [DataContract] attribute, collection classes with the [CollectionDataContract] attribute and the properties with the [DataMember] attribute.</p> <pre><code>[CollectionDataContract] public class People : List&lt;Person&gt; { } [DataContract] public class Person { public Person() { } [DataMember] public int Id{ get; set; } [DataMember] public string Name { get; set; } } </code></pre> <p>Here is a helper class to serialize (To) and deserialize (From) </p> <pre><code>using System.Runtime.Serialization; using System.Runtime.Serialization.Json; public class jsonHelper { public static string To&lt;T&gt;(T obj) { string retVal = null; System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType()); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, obj); retVal = Encoding.Default.GetString(ms.ToArray()); } return retVal; } public static T From&lt;T&gt;(string json) { T obj = Activator.CreateInstance&lt;T&gt;(); using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json))) { System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType()); obj = (T)serializer.ReadObject(ms); } return obj; } } </code></pre> <p>So take your json above and send it to the From method in the jsonHelper class above</p> <pre><code>People peeps = jsonHelper.From&lt;People&gt;(input); </code></pre>
 

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