gpt4 book ai didi

ios - XML解析中URL没有响应-Alamofire Swift 5

转载 作者:行者123 更新时间:2023-12-01 22:09:36 30 4
gpt4 key购买 nike

我将XMLMapperAlamoFire请求一起使用以获取响应。 URL在浏览器上运行良好,但是当我尝试快速使用时,它将跳过该功能。即使我无法调试响应。它在解析之前,不会从URL获取任何数据或响应。任何的想法 ??

func xmlParser() {
let urlXml = "https://images.apple.com/main/rss/hotnews/hotnews.rss"

Alamofire.request(urlXml, method: .get).responseXMLObject { (response: DataResponse<RSSFeed>) in
let rssFeed = response.result.value
print(rssFeed?.channel?.items?.first?.title ?? "nil")
}
}

最佳答案

您的模型似乎有问题。我设法映射了此链接的响应。

尝试使用以下结构,并将其与您的结构进行比较以查看差异:

class RSSFeed: XMLMappable {
var nodeName: String!

var channel: Channel?

required init?(map: XMLMap) {}

func mapping(map: XMLMap) {
channel <- map["channel"]
}
}

class Channel: XMLMappable {
var nodeName: String!

var title: String?
var link: URL?
var description: String?
var language: String?
var copyright: String?
var pubDate: String?
var lastBuildDate: String?
var category: String?
var generator: String?
var docs: URL?
var items: [Item]?

required init?(map: XMLMap) {}

func mapping(map: XMLMap) {
title <- map["title"]
link <- (map["link"], XMLURLTransform())
description <- map["description"]
language <- map["language"]
copyright <- map["copyright"]
pubDate <- map["pubDate"]
lastBuildDate <- map["lastBuildDate"]
category <- map["category"]
generator <- map["generator"]
docs <- (map["docs"], XMLURLTransform())
items <- map["item"]
}
}

class Item: XMLMappable {
var nodeName: String!

var title: String?
var link: URL?
var description: String?
var pubDate: String?

required init?(map: XMLMap) {}

func mapping(map: XMLMap) {
title <- map["title"]
link <- (map["link"], XMLURLTransform())
description <- map["description"]
pubDate <- map["pubDate"]
}
}

希望这可以帮助。

关于ios - XML解析中URL没有响应-Alamofire Swift 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58285133/

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