How to get data that's inside NSCFDictionary returned by SLRequest on OSX?

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

I make this facebook request:

SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook                                                     requestMethod:SLRequestMethodGET                                                               URL:[NSURL URLWithString:@"https://graph.facebook.com/fql"]                                                        parameters:[NSDictionary dictionaryWithObject:@"SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" forKey:@"q"]];  [facebookRequest setAccount:_facebookAccount];  [facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {      if(!error){            id json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];            NSLog(@"%@", [json class]);             //NSCFDictionary. How can i get the data that's inside this?      }else{            NSLog(@"error fb");             }      }]; 

Any thoughts on how to retrieve the data inside the NSCFDictionary? I've tried [json valueforKey...] but nothing

回答1:

Use NSDictionary's -objectForKey: method:

id json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil]; if ([json isKindOfClass:[NSDictionary class]]) {     NSDictionary *dict = (NSDictionary*)json;     for (NSString *key in dict) {         id object = [dict objectForKey:key];         NSLog(@"The object for key \"%@\" is: %@", key, object);     } } 

Incidentally, it wouldn't take much to figure out that a NSCFDictionary can be treated like a NSDictionary. Here's one SO question that explains that: What is an NSCFDictionary? Once you know that, you can easily figure out how to deal with it by looking at the documentation for NSDictionary.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!