我正在尝试将 RestKit 0.20 集成到我的项目中,例如,我使用 google rss 阅读器作为示例项目。
这是对 Xml
/ /category> &
的响应
这是我必须从中获取数据的 Xml。
RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[新闻类]]; [articleMapping addAttributeMappingsFromDictionary:@{@"title":@"title",@"link":@"link",@"guid":@"guid",@"pubDate":@"pubDate",@"description" : @“描述” }];
NSURL* url = [[NSURL alloc]initWithString:@"http://news.google.com"];
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:url];
NSURLRequest* request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:@"/?output=rss" parameters:nil];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:articleMapping pathPattern:nil keyPath:@"item" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"Load collection of Articles: %@", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Operation failed with error: %@", error);
}];
[objectRequestOperation start];
以上是我用来获取数据的代码当我运行应用程序时出现以下错误
我 restkit.network:RKObjectRequestOperation.m:174 GET ' http://news.google.com/?output=rss ' 2013-05-28 12:24:15.076 TestApp[8940:15203] E restkit.network:RKObjectRequestOperation。 m:569 对象请求失败:基础 HTTP 请求操作失败并出现错误:错误域 = org.restkit.RestKit.ErrorDomain 代码 = -1016 “预期内容类型 {( “application/xml”,“application/x-www-form- urlencoded", "application/json" )}, got application/rss+xml" UserInfo=0xa80a3d0 {NSLocalizedRecoverySuggestion=NFE/1.0Top Stories - Google 新闻
任何人都可以帮助