Click here to Skip to main content
15,921,531 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
{ "data": [
],
"summary": {
"total_count": 140
}
}

XML
FacebookFriendsModel friends = new FacebookFriendsModel();

                   var client = new FacebookClient(Session["accessToken"].ToString());
                   dynamic fbresult = client.Get("me/friends");
                   var data = fbresult["data"].ToString();

                   friends.friendsListing = JsonConvert.DeserializeObject<List<FacebookFriend>>(data);



my model
C#
public class FacebookFriendsModel
   {
       public List<FacebookFriend> friendsListing { get; set; }
   }
   public class FacebookFriend
   {
       public string name { get; set; }
       public string id { get; set; }
  public int total_count{ get; set; }
   }



help me.
Posted
Updated 29-Aug-14 1:04am
v2

1 solution

Looking at the JSON structure, it doesn't conform to your Model definition. You JSON corresponds to this object structure:

C#
public class Summary
{
    public int total_count { get; set; }
}

public class RootObject
{
    public List<object> data { get; set; }
    public Summary summary { get; set; }
}


If you rename 'RootObject' to FacebookFriendsModel, and 'data' to FacebookFriend, using JSON attributes, you'll get:

C#
public class Summary
{
    public int total_count { get; set; }
}


public class FacebookFriendsModel
{
    [JsonProperty("data")]
    public List<FacebookFriend> FacebookFriends { get; set; }
    public Summary summary { get; set; }
}


The biggest difference is that total_count is not part of FacebookFriend, but of the parent Model, since it's outside of the JSON array.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900