2016-04-08 32 views
0

我正在使用RestKitRealm开发应用程序。 解析JSON并将对象保存到领域数据库是没有问题的。用restKit解析xml

我现在的问题是解析XML并将其保存到数据库。 我试过RKXMLReaderSerializationXMLReader,但是XMLReader太旧了,因为它仍然在使用ARC。

没有这两个框架我#m的收到此错误的:

NSLocalizedDescription=Expected content type {(
    "application/x-www-form-urlencoded", 
    "application/json" 
)}, got application/rss+xml} 

如何新增rss+xml

编辑: 我想我必须添加rss+xml作为RestKit的MIME类型,但是如何?

下面的代码是我的电话加载我的NewsFeed,我从上面收到错误消息。

static func loadNewsFromServer() { 
     RKObjectManager.sharedManager().getObjectsAtPath(serverURL, 
      parameters: nil, 

      success: { (operation: RKObjectRequestOperation!, result: RKMappingResult!) -> Void in 

       //handle sucess 
      }, 

      failure: { (operation: RKObjectRequestOperation!, error: NSError!) -> Void in 
       print(error) 
      } 
     ) 
    } 

ResponseDescriptor:

let newsResponseDescriptor = RKResponseDescriptor(mapping: News.restKitObjectMapping(), method: RKRequestMethod.GET, pathPattern: serveURL, keyPath: nil, statusCodes: RKStatusCodeIndexSetForClass(RKStatusCodeClass.Successful)) 

是否有任何的可能性来解析XML与restKit?

非常感谢!

+0

默认的'NSXMLParser'呢? – Wain

+0

解析前我会得到错误。我再次编辑这个问题 – kimbl

回答

0

你需要做的:(OBJ中-C和迅速的提供,虽然我还没有检查的确切语法和类型在iPad ...)

[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:@"rss+xml"]; 

RKMIMETypeSerialization.registerClass(RKXMLReaderSerialization.self, forMIMEType: "rss+xml") 

和:

[myObjectManager setAcceptHeaderWithMIMEType:@"rss+xml"]; 

myObjectManager.setAcceptHeaderWithMIMEType("rss+xml") 
+0

我试过这个解决方案allready,但是如果我导入'import RKXMLReaderSerialization',我会从xcode得到以下错误:'不能构建Objective-C模块RKXMLReaderSerialization',我认为这是因为RKXMLReaderSerialization链接到XML阅读器。但是XML-Reader是5年前最后更新的版本,并且仍在使用ARC ... – kimbl

+0

因此,您需要查找/创建可用于“RKMIMETypeSerialization”的不同XML序列化程序。 RestKit + XML + swift不会一直使用到目前为止我认为... – Wain

+0

其实我得到JSON的响应:)现在的问题是与RequestParameter api的responseDescriptor。你能检查我的新问题吗? http://stackoverflow.com/questions/36721011/restkit-get-request-with-queryparameter-no-matching-responsedescriptor – kimbl