zoukankan      html  css  js  c++  java
  • 使用 RestKit 0.10 映射 RSS

    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

  • 相关阅读:
    Javascript FP-ramdajs
    微信小程序开发
    SPA for HTML5
    One Liners to Impress Your Friends
    Sass (Syntactically Awesome StyleSheets)
    iOS App Icon Template 5.0
    React Native Life Cycle and Communication
    Meteor framework
    RESTful Mongodb
    Server-sent Events
  • 原文地址:https://www.cnblogs.com/iihe602/p/2887037.html
Copyright © 2011-2022 走看看