作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 SWXMLHASH 或 AEXML 库从我博客的 RSS URL 解析 XML。我为此找到了解决方案,但是当我尝试该解决方案时,我的应用程序崩溃了。是遇到的问题:fatal error: unwrapping an Optional value unwhile unwrapping an Optional value unexpectedly found nil
(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)
}
}
关于ios - 如何将 Alamofire 与 AEXML 或 SWXMLHASH 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44168495/
我是一名优秀的程序员,十分优秀!