gpt4 book ai didi

Android Kotlin Retrofit + SimpleXMLConverter ElementList 无法正确解析

转载 作者:行者123 更新时间:2023-11-29 01:02:38 25 4
gpt4 key购买 nike

我正在尝试解析一些播客 xml 提要,但无法获取所有类别和其他具有相同名称的多个字段。

供稿示例:http://demo3984434.mockable.io/cast

<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>Podcast Title</title>
<link>http://link.com</link>
<language>en-us</language>
<itunes:subtitle>Subtitle!!!</itunes:subtitle>
<itunes:author>Author Name</itunes:author>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Comedy</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Society &amp; Culture</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Games &amp; Hobbies/Video Games</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">TV &amp; Film</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Music</media:category>
<itunes:category text="Comedy"/>
<itunes:category text="Society &amp; Culture"/>
<itunes:category text="Games &amp; Hobbies"/>
<itunes:category text="Video Games"/>
<itunes:category text="TV &amp; Film"/>
<itunes:category text="Music"/>
</channel>
</rss>

RSSFeed.kt:

@Root(name = "rss", strict = false)
class RSSFeed {

@field:Element(name = "channel")
var mFeedChannel: FeedChannel? = null
}

FeedChannel.kt

@Root(name = "channel", strict = false)
open class FeedChannel {

@field:Element(name = "title")
var mTitle: String? = null

@field:Element(name = "link")
var mLink: String? = null

@field:Element(name = "subtitle")
var mSubtitle: String? = null

@field:Element(name = "author")
var mAuthor: String? = null

@field:ElementList(entry = "category", inline = true)
var mCategories: List<Category>? = null

@Root(name = "category", strict = false)
class Category {

@field:Element(name = "category")
var category: String? = null
}
}

但类别列表元素始终为空: enter image description here

最佳答案

找到解决方案:

更改了@field:Element 字段并使用String 代替另一个类Category。感谢@DaveThomas

@Root(name = "channel", strict = false)
class FeedChannel {

@field:Element(name = "title")
var mTitle: String? = null

@field:Element(name = "link")
var mLink: String? = null

@field:Element(name = "subtitle")
var mSubtitle: String? = null

@field:Element(name = "author")
var mAuthor: String? = null

@field:ElementList(entry = "category", type = String::class, inline = true)
var mCategories: List<String>? = null

}

关于Android Kotlin Retrofit + SimpleXMLConverter ElementList 无法正确解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50031409/

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