[英]How can I combine Alamofire with AEXML or SWXMLHASH
我想从URL中解析XML,这是我的博客的RSS和SWXMLHASH或AEXML库。 我找到了解决方案但是当我尝试解决方案时,我的应用程序崩溃了。 这是遇到的问题: fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
我的代码在viewDidLoad中:
` Alamofire.request("http://myblog.com/feed").responseJSON { response in
if let data = response.data {
let xml = SWXMLHash.parse(data)
let news = xml["rss"]["channel"]["item"][0]["title"].element?.text
print(news!)
}
}
`
还有其他解决方案吗? 我不想使用NSXMLParser,我想使用这些类或者如果它存在任何最新的库,我可以使用。
谢谢您的帮助!
采用
Alamofire.request("http://myblog.com/feed").response
不是Alamofire.request("http://myblog.com/feed").responseJSON
我使用了AEXML ..试试这个
Alamofire.request("http://myblog.com/feed").response { res in
guard let xml = res.data else {
return
}
var options = AEXMLOptions()
options.parserSettings.shouldProcessNamespaces = false
options.parserSettings.shouldReportNamespacePrefixes = false
options.parserSettings.shouldResolveExternalEntities = false
do {
let xmlDoc = try AEXMLDocument(xml: xml, options: options)
print(xmlDoc.root["channel"]["item"]["title"].value!)
} catch let error {
print(error)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.