【发布时间】:2015-01-06 07:07:58
【问题描述】:
我正在使用AFNetworking 调用网络服务并将返回数据保存在NSDictionary 对象中。但即使数据成功登录NSLog(),也没有存储任何内容。
这是我的字典:
@property (strong, nonatomic) NSDictionary *newsItems;
这是我的代码:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"key": @"keyy", @"q": @"ads" };
[manager POST:BaseURLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.newsItems = (NSDictionary *) responseObject;
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
【问题讨论】:
-
你的代码是正确的,你能把
NSLog和self.newsItems和responseObject放在一起吗? -
它可能会返回
NSArray或NSDictionary。在转换之前检查响应类型。 -
请在控制台中发布
responseObject的NSLog。 -
它应该返回字典数组
标签: ios objective-c ios7 afnetworking