【发布时间】:2021-12-03 06:34:59
【问题描述】:
我尝试使用 XML SimpleXML Converter 解析从 https://www.w3schools.com/xml/simple.xml 获得的 xml,但出现异常
org.simpleframework.xml.core.PersistenceException:构造函数与类 com.example.nbrbcurrency.retrofit.models.Food 不匹配
我的 POJO 的
import org.simpleframework.xml.ElementList
import org.simpleframework.xml.Root
@Root(strict = false, name = "breakfast_menu")
data class BreakFastMenu @JvmOverloads constructor(
@field:ElementList(inline = true)
var foodList : List<Food>
)
和
import org.simpleframework.xml.Element
import org.simpleframework.xml.Root
@Root(name = "food")
data class Food @JvmOverloads constructor(
@field:Element(name = "name")
var name: String,
@field:Element(name = "price")
var price: String,
@field:Element(name = "description")
var description: String,
@field:Element(name = "calories")
var calories: String)
xml
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
【问题讨论】:
标签: android xml kotlin simple-xml-converter