【发布时间】:2019-10-31 16:51:08
【问题描述】:
我正在使用 retrofit2 和简单的 xml 解析器将 xml 值解析为类。
但是,我从来没有遇到过这些 inline(?) 标签。 api 返回了一些东西,但是响应的主体是空的。
xml 如下所示。
<?xml version="1.0" encoding="ISO-8859-1"?>
<Book title="Title Name" ver="20190513001" coverimg="PPO01.jpg" bookcode="PPO01">
<chapters count="1">
<chapter endflag="000" thumbnail="PPO0101_TN.jpg" chaptercode="PPO0101" num="1">
<chaptername>ChapterName</chaptername>
<movies count="1">
<movie num="1" name="Movie Name" url="Some Url" type="AR">
<directions count="0"/>
</movie>
</movies>
</chapter>
</chapters>
</Book>
我的响应代码如下所示。
根对象。
@Root(name = "Book", strict = false)
public class XmlBook implements Serializable {
@Element(name = "title")
private String title;
@Element(name = "ver")
private String ver;
@Element(name = "coverimg")
private String coverimg;
@Element(name = "bookcode")
private String bookcode;
@Element(name = "chapters")
private XmlChapterHeader chapters;
}
“章节”对象。
@Root(name = "chapters", strict = false)
public class XmlChapterHeader {
@Element(name = "count")
private int count;
@ElementList(name = "chapter", inline = true)
private List<XmlChapter> chapter;
}
“章节”对象。
@Root(name = "chapter", strict = false)
public class XmlChapter {
@Element(name = "num")
private String num;
@Element(name = "chaptercode")
private String chaptercode;
@Element(name = "thumbnail")
private String thumbnail;
@Element(name = "endflag")
private String endflag;
@Element(name = "chaptername")
private String chaptername;
@Element(name = "movies")
private XmlMovieContainer movies;
}
“电影”对象。
@Root(name = "movies", strict = false)
public class XmlMovieContainer {
@ElementList(name = "movies", inline = true)
List<XmlMovie> movie;
}
最后是“电影”对象 .
@Root(name = "movie", strict = false)
public class XmlMovie {
@Element(name = "directions")
private int directions;
}
我在谷歌上搜索过这个问题,但找不到有效的解决方案。请帮忙!
【问题讨论】:
标签: android xml-parsing retrofit2