在 Android 上使用简单与和改造反序列化字符串元素列表

问题描述 投票:0回答:1

我正在使用 simple-xml 库 (https://simple.sourceforge.net/home.php) 反序列化字符串元素列表。

<Parent>
  <PropertyList>
    <Entry>image/png</Entry>
    <Entry>application/atom+xml</Entry>
    <Entry>application/json;type=utfgrid</Entry>

我成功反序列化的是:

data class PropertyList(
   @field:ElementList(name = "Entry", inline = true)
   var entries: List<Entry> = mutableListOf()
)

@Root(name = "Entry", strict = false)
class Entry(
   @field:Text
   var entry: String? = null
)

但是我想弄清楚是否可以删除额外的 Entry 类并反序列化为字符串列表:

data class PropertyList(
   @field:ElementList(name = "Entry", inline = true)
   var entries: List<String> = mutableListOf()
)

当我尝试这样做时,我得到了一个空列表。这可能吗?

android retrofit simplexml
1个回答
0
投票

这应该可以解决问题:

data class PropertyList(
   @field:ElementList(name="Entry", inline=true, required=false, type=String::class)
   var entries: List<Entry> = mutableListOf()
)
© www.soinside.com 2019 - 2024. All rights reserved.