gpt4 book ai didi

swift - 使用带有 Alamofire 的 SWXMLHash 解析 xml 时出错

转载 作者:搜寻专家 更新时间:2023-10-31 22:18:28 24 4
gpt4 key购买 nike

我在 Swift 4 中使用 pod

pod 'SWXMLHash', '~> 4.0.0'
pod 'Alamofire', '~> 4.5'

当我使用以下代码解析 XML 时,出现错误:

Type 'XMLIndexer' does not conform to protocol 'Sequence'

代码:

Alamofire.request("https://itunes.apple.com/us/rss/topgrossingapplications/limit=10/xml").response { response in
debugPrint(response)

guard let data = response.data else {
return
}

let xml = SWXMLHash.parse(data)
let nodes = xml["feed"]["entry"]
for node in nodes {
print(node["title"].text)
}
}

我正在尝试从上面的 iTunes XML URL 访问“条目”标签列表。如果有任何方法可以访问和初始化类/结构中的条目列表,请帮助。

最佳答案

根据文档你需要添加all:

Alamofire.request("https://itunes.apple.com/us/rss/topgrossingapplications/limit=10/xml").response { response in
debugPrint(response)

guard let data = response.data else {
return
}

let xml = SWXMLHash.parse(data)
let nodes = xml["feed"]["entry"]
for node in nodes.all {
print(node["title"]?.text)
}
}

关于swift - 使用带有 Alamofire 的 SWXMLHash 解析 xml 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48076862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com