Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edit2:</strong> </p> <p>Referring <a href="https://gist.github.com/973510" rel="nofollow">https://gist.github.com/973510</a>, its clear from the returned json, that if a particular facebook message doesnt have any likes, then the returned json doesnt contain a property called <code>likes</code>. Hence <code>likes</code> property of <code>sdata object</code> is null. Thats just how the server returns the data. </p> <p>There are two ways you can deal with this. Either do a manual check whether <code>likes</code> is null. Or initialize the likes property in the sdata constructor. And initialize the likesdata list in the likesdatacollection constructor. </p> <p>Code:</p> <pre><code>public class sdata { // other properties public likedatacollection likes { get; set; } public sdata() { likes = new likedatacollection(); } } public class likedatacollection { public List&lt;likesdata&gt; data { get; set; } public likedatacollection() { data = new List&lt;likesdata&gt;(); } } </code></pre> <p>This way, even if fb doesnt return any likes, the constructors will initialize the properties, so they will not be null. You can then check whether <code>likes.data.Count &gt; 0</code>. If yes, then fb returned likes, else fb didnt return likes.</p> <p><strong>Edit1:</strong></p> <p>From the OP's comment, its clear that the json is properly formed. Meaning, the json is as retrieved from some server api. Therefore it is the <code>sdata</code> class that is the culprit. Please look at <a href="https://gist.github.com/973457" rel="nofollow">this gist</a> for the full solution. </p> <p>The short version. For the simplest case, your c# classes need to follow the exact same structure as your json. As per the json, <code>data</code> has a property called <code>likes</code>. the <code>likes</code> object has a property called <code>data</code> which is an array of objects with properties id and name. </p> <p>So your c# class <code>sdata</code> should have a property called <code>likes</code> of type <code>likesdatacollection</code>. This class should have a property <code>data</code> of type <code>List&lt;likesdata&gt;</code>... </p> <p>Off topic, people generally seem to prefer Json.Net ... so you may want to use that. The reason I use it is because I need it to work in a .Net 2.0 code base ... </p>
 

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