如何让我的朋友从facebook图api中获取我的模型总计数

如何让我的朋友从facebook图api中获取我的模型总计数

问题描述:

{
数据:[

],

摘要:{

total_count:140
}

}



{ "data": [
],
"summary": {
"total_count": 140
}
}

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

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.

查看JSON结构,它不符合您的模型定义。 You JSON对应于此对象结构:



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

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

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





如果你使用JSON属性将'RootObject'重命名为FacebookFriendsModel,将'data'重命名为FacebookFriend,你得到:





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

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; }
}





最大的区别是total_count不是FacebookFriend的一部分,而是父模型的一部分,因为它在外面JSON数组。



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.