gpt4 book ai didi

iphone - Facebook 结果变成一个 NSArray

转载 作者:行者123 更新时间:2023-11-29 13:22:26 28 4
gpt4 key购买 nike

我正在使用 Facebook api 获取用户的 friend 姓名、UID 和生日。我遇到的问题是,一旦我得到结果,我该如何获得这些值。意思是,我想获取每个返回值的用户名和生日?

这段代码一直让我崩溃

//set query
NSString *query = @"SELECT uid, name, birthday_date FROM user WHERE uid IN " @"(SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)";

// Set up the query parameter
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];

[FBRequestConnection startWithGraphPath:@"/fql"
parameters:queryParam
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
}
else {
NSLog(@"Result: %@", result);
NSArray *friendInfo = (NSArray *) [result objectForKey:@"data"];
NSArray *arryData3 = [[NSArray alloc] initWithArray:friendInfo];
NSLog(@"[friendInfo count]: %d ... [arryData3 count]: %d ...",[friendInfo count],[arryData3 count]);
for (int i=0; i<[arryData3 count]; i++) {
NSArray *bdayArray = [[NSArray alloc] initWithArray:[arryData3 objectAtIndex:i]];
//CODE CRASH HERE!!!!
NSString *bdayStr = [bdayArray objectAtIndex:0];
NSString *nameStr = [bdayArray objectAtIndex:1];
}
}
}];

这是我的崩溃日志的样子

data(
{
"birthday_date" = "01/06";
name = "John Doe";
uid = 555555;
},
{
"birthday_date" = "09/01/1984";
name = "Mrs. Smith";
uid = 4444444;
},
)
[friendInfo count]: 2 ... [arryData3 count]: 2 ...
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSArray initWithArray:range:copyItems:]: array argument is not an NSArray'
*** First throw call stack:
(0x168f052 0x1cabd0a 0x167fe0b 0x15e8170 0x16ca2 0x27c03 0x26c7e 0x2444e 0x2927e 0x296e7 0xfc1a59 0xfbfe94 0xfc0eb7 0xfbfe4f 0xfbffd5 0xf04f6a 0x3964bbd 0x3a315ea 0x395b298 0x3a3116b 0x395b137 0x166397f 0x15c6b73 0x15c6454 0x15c5db4 0x15c5ccb 0x3bd1879 0x3bd193e 0x5cca9b 0x2038 0x1f95)

最佳答案

对于任何可能对 future 感兴趣的人。这就是您如何在 Facebook 的结果中获得个人值(value)。

NSLog(@"Result: %@", result);
NSArray *friendInfo = (NSArray *) [result objectForKey:@"data"];
NSLog(@"[friendInfo count]: %d ....",[friendInfo count]);
for (int i=0; i<[friendInfo count]; i++)
{
NSMutableString *userNameStr = [NSMutableString stringWithFormat:@"%@", [[friendInfo objectAtIndex:i] objectForKey:@"name"]];
NSMutableString *userDateStr = [NSMutableString stringWithFormat:@"%@", [[friendInfo objectAtIndex:i] objectForKey:@"birthday_date"]];
NSLog(@"userNameStr: %@ ... userDateStr: %@ ...", userNameStr,userDateStr);
//From this point onwards you can put these individual strings into an array
//and if you had defined the array globally you can get to these results from
//any function in your code
}

关于iphone - Facebook 结果变成一个 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14085419/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com