本文介绍了如何让我的朋友从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 modelpublic 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. 这篇关于如何让我的朋友从facebook图api中获取我的模型总计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 11:39