解析 Facebook 好友列表 [英] Parse Facebook friends list
问题描述
直到统一api,我都用这段代码来解析Facebook的好友列表:
Up until the unified api, I have used this code to parse Facebook's friends list:
var list = new List<FacebookFriend>();
var graphObject = result as FBGraphObject;
using (var array = (NSMutableArray)graphObject[new NSString("data")])
{
for (uint i = 0; i < array.Count; i++)
{
using (var friend = new NSDictionary(array.ValueAt (i)))
{
friends.Add (new FacebookFriend
{
ID = friend.ObjectForKey (new NSString ("uid")).ToString (),
Name = friend.ObjectForKey (new NSString ("name")).ToString (),
});
}
}
}
脸书好友:
public class FacebookFriend
{
public string ID { get; set; }
public string name { get; set; }
}
数组如下:
array {( { id = 100009010208340; name = "Patricia Amijajbjhcdj Wongsky"; }, { id = 100009036398265; name = "Patricia Amijcfcihbfe Vijayvergiyasen"; }, {10600009010208350606000000000000000000000000000000000000000000001000000000000000000000000000001)}
array {( { id = 100009010208340; name = "Patricia Amijajbjhcdj Wongsky"; }, { id = 100009036398265; name = "Patricia Amijcfcihbfe Vijayvergiyasen"; }, { id = 100009086915834; name = "Elizabeth Amijhfiaehcd Bharambesky"; } )}
但是现在 NSDictionary 的保护级别发生了变化并且此代码中断了.我尝试使用一些工厂方法,但没有成功.
But now the protection level of NSDictionary changed and this code breaks. I've tried using some factory methods instead but with no success.
有谁知道在这种情况下应该用什么代替
Does anyone know what should be used in this case instead of
new NSDictionary(array.ValueAt (i)))
谢谢
推荐答案
应该是这样的:
Runtime.GetNSObject
旁注:在循环内创建相同的 NSString
常量效率不高.您应该执行以下操作:
Side note: creating the same NSString
constants inside a loop is not efficient. You should do something like:
using (var uid = new NSString ("uid"))
using (var name = new NSString ("name")) {
for (uint i = 0; i < array.Count; i++) {
using (var friend = Runtime.GetNSObject<NSDictionary> (array.ValueAt (i))) {
friends.Add (new FacebookFriend
{
ID = friend.ObjectForKey (uid).ToString (),
Name = friend.ObjectForKey (name).ToString (),
});
}
}
这篇关于解析 Facebook 好友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!