我正在使用 AFNetworking
调用 Web 服务并将返回数据保存在 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(@"RESPONSE : %@", operation.responseString);
其次,如果您的 Web 服务应该返回一个字典数组,那么您应该在字典上声明一个数组。
@property (strong, nonatomic) NSArray *newsItems;
代替
@property (strong, nonatomic) NSDictionary *newsItems;
关于ios - 无法保存 AFNetworking responseObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27793764/