title: Deserialize Json to Class that implements Ienumerable in Asp.net
body: <p>I've below function which fetches facebook data and return it as string.</p>
  
  <pre><code>public static string GetUserNewsFeed(string strAccessToken)
  {
      Dictionary&lt;string, object&gt; PostDetail = new Dictionary&lt;string, object&gt;();
      DateTime CreatedDateTime = DateTime.Today.AddDays(-90);
      var epoch = (CreatedDateTime.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
      PostDetail.Add("Posts", "SELECT post_id,source_id FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') and (likes.count &gt; 0 or comments.count &gt; 0) and created_time &gt; " + epoch);
      PostDetail.Add("PostComments", "select post_id,fromid from comment where post_id in (select post_id from #Posts)");
      PostDetail.Add("PostLikes", "SELECT object_id,post_id,user_id FROM like WHERE post_id in (select post_id from #Posts)");
      string Json = HttpUtility.UrlEncode(Newtonsoft.Json.JsonConvert.SerializeObject(PostDetail));       
      return RunFQLQuery(Json, strAccessToken);
  }
  </code></pre>
  
  <p>Here's the code that calls this function and convert it to Jobject using Json.NET :</p>
  
  <pre><code>strFeed = FacebookAPI.GetUserNewsFeed(Convert.ToString(Session["access_token"]));
  JObject objStreamData = JObject.Parse(strFeed);
  var PostResponse = objStreamData.SelectToken("data[0]");
  </code></pre>
  
  <p>Below line deserialize it to NewsFeedPost Class :</p>
  
  <pre><code>var Posts = JsonConvert.DeserializeObject&lt;NewsFeedPost&gt;(PostResponse.ToString());
  </code></pre>
  
  <p>And below is the class :</p>
  
  <pre><code>public class NewsFeedPost 
  {      
      public string name { get; set; }
      public List&lt;Post&gt; fql_result_set { get; set; }
  }
  public class Post
  {
      public string post_id { get; set; }
      public string source_id { get; set; }
  }
  </code></pre>
  
  <p>Now problem is when I change my NewsFeedPost class to below it throws error "<strong>Cannot deserialize JSON object into type 'BAL.NewsFeedPost'</strong>" :</p>
  
  <pre><code>public class NewsFeedPost : IEnumerable&lt;Post&gt;
  {      
      public string name { get; set; }
      public List&lt;Post&gt; fql_result_set { get; set; }
      public IEnumerator&lt;Post&gt; GetEnumerator()
      {
          foreach (Post item in fql_result_set)
          {
              yield return item;
          }
      }
      IEnumerator IEnumerable.GetEnumerator()
      {
          return GetEnumerator();
      }
  
  }
  </code></pre>
  
  <p>Below is the sample of Json Response :</p>
  
  <pre><code>{
    "data": [
  {
    "name": "Posts",
    "fql_result_set": [
      {
        "post_id": "1"
      },
      {
        "post_id": "2"
      }
    ]
  },
  {
    "name": "PostComments",
    "fql_result_set": [
      {
        "post_id": "3",
        "fromid": 4
      },
      {
        "post_id": "5",
        "fromid": 6
      }
    ]
  },
  {
    "name": "PostLikes",
    "fql_result_set": [
      {
        "object_id": 7,
        "post_id": "8",
        "user_id": 9
      },
      {
        "object_id": 10,
        "post_id": "11",
        "user_id": 12
      }
    ]
  }
  ]
  }
  </code></pre>
  
  <p>I just want to enumerate through list and create comma delimited list and save it to db. Can anybody throw some light what needs to be done? How can I get the Count and Length Property for List?</p>