Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>[Update]</strong><br/> I've just realized why you weren't receiving results back... you have a missing line in your <code>Deserialize</code> method. You were forgetting to assign the results to your <code>obj</code> :</p> <pre><code>public static T Deserialize&lt;T&gt;(string json) { using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T)); return (T)serializer.ReadObject(ms); } } </code></pre> <p>Also, just for reference, here is the <code>Serialize</code> method : </p> <pre><code>public static string Serialize&lt;T&gt;(T obj) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, obj); return Encoding.Default.GetString(ms.ToArray()); } } </code></pre> <hr> <p><strong>Edit</strong></p> <p>If you want to use Json.NET here are the equivalent Serialize/Deserialize methods to the code above..</p> <p>Deserialize:</p> <pre><code>JsonConvert.DeserializeObject&lt;T&gt;(string json); </code></pre> <p>Serialize:</p> <pre><code>JsonConvert.SerializeObject(object o); </code></pre> <p>This are already part of Json.NET so you can just call them on the JsonConvert class.</p> <p><strong>Link: <a href="http://james.newtonking.com/projects/json/help/index.html?topic=html/SerializingJSON.htm" rel="noreferrer">Serializing and Deserializing JSON with Json.NET</a></strong></p> <hr> <p><br/>Now, the reason you're getting a StackOverflow is because of your <code>Properties</code>.</p> <p>Take for example this one : </p> <pre><code>[DataMember] public string unescapedUrl { get { return unescapedUrl; } // &lt;= this line is causing a Stack Overflow set { this.unescapedUrl = value; } } </code></pre> <p>Notice that in the <code>getter</code>, you are returning the actual property (ie the property's getter is calling itself over and over again), and thus you are creating an infinite recursion.</p> <hr> <p>Properties (in 2.0) should be defined like such : </p> <pre><code>string _unescapedUrl; // &lt;= private field [DataMember] public string unescapedUrl { get { return _unescapedUrl; } set { _unescapedUrl = value; } } </code></pre> <p>You have a private field and then you return the value of that field in the getter, and set the value of that field in the setter.</p> <hr> <p>Btw, if you're using the 3.5 Framework, you can just do this and avoid the backing fields, and let the compiler take care of that : </p> <pre><code>public string unescapedUrl { get; set;} </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