android - Android Kotlin Retrofit + SimpleXMLConverter ElementList 解析不正确
问题描述
我正在尝试解析一些播客 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 & Culture</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Games & Hobbies/Video Games</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">TV & 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 & Culture"/>
<itunes:category text="Games & Hobbies"/>
<itunes:category text="Video Games"/>
<itunes:category text="TV & 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
}
}
解决方案
找到了解决方案:
更改了 @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
}
推荐阅读
- sql - Visual Studio 2017 无法加载解决方案 “Package”包没有正确加载
- python - 没有找到 coremltools==0.8 的匹配分布(来自 turicreate)
- shinydashboard - r flexdashboard 问题与 arules 反应输入
- c# - 检查条件并相应地删除动态控件c#
- google-bigquery - StackDriver 中的 BQ 审计日志 ::jobCompletedEvent.job.jobStatistics 中缺少字段
- c - 如何找到默认网关的地址和面向它的本地地址?
- javascript - 我正在使用角度代码调用其余 api 并将其显示在屏幕上
- ios - 无法在 Xcode Storyboard 中调整 UITextField 的大小
- css - 当项目少于列时将 CSS 网格居中
- android - 如何在 Firebase-ui ListVeiw 中实现点击监听器?