RestKit支持的类型:
NSString * const RKMIMETypeJSON = @"application/json"; NSString * const RKMIMETypeFormURLEncoded = @"application/x-www-form-urlencoded"; NSString * const RKMIMETypeXML = @"application/xml"; NSString * const RKMIMETypeTextXML = @"text/xml";
对于RSS,虽然是xml格式,但MIMEType会被认为是 application/rss+xml,所以,会提示没有找到对应的解析类
需要增加两行代码,让rss按application/xml,来解析,即可
- (void)viewDidLoad { [super viewDidLoad]; RKURL *baseUrl = [RKURL URLWithBaseURLString:kBASE_URL]; RKObjectManager *manager = [RKObjectManager managerWithBaseURL:baseUrl]; RKObjectMapping *songMapping = [RKObjectMapping mappingForClass:[Song class]]; [songMapping mapKeyPath:@"title" toAttribute:@"title"]; [manager.mappingProvider setMapping:songMapping forKeyPath:@"rss.channel.item"]; Class class = NSClassFromString(@"RKXMLParserXMLReader"); [[RKParserRegistry sharedRegistry] setParserClass:class forMIMEType:@"application/rss+xml"]; [manager loadObjectsAtResourcePath:kRESOURCE_PATH delegate:self]; }
RKXMLParserXMLReader是xml的解析类
查看全部源代码,https://github.com/iihe602/Using-RestKit-Parse-RSS