- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Retrofit 从 URL 获取书籍 xml 数据。但是当应用程序运行时,它显示错误。我是新来的所以请帮助我。这是错误信息:
02-20 23:06:37.943 23835-23835/com.santossingh.reader E/error:
org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=true, name=work, required=true, type=void) on field 'works' public java.util.List com.santossingh.reader.AWS.GoodReadsModels.Results.works for class com.santossingh.reader.AWS.GoodReadsModels.Results at line 2
这是 XML 文件结构以及我的模型和类:
1- URL XML 文件的结构:
<?xml version="1.0" encoding="UTF-8"?>
<GoodreadsResponse>
<Request>
<authentication>true</authentication>
<key><![CDATA[xxxxx]]></key>
<method><![CDATA[search_index]]></method>
</Request>
<search>
<query><![CDATA[business]]></query>
<results-start>1</results-start>
<results-end>20</results-end>
<total-results>109755</total-results>
<source>Goodreads</source>
<query-time-seconds>0.22</query-time-seconds>
<results>
<work>
<id type="integer">17624817</id>
<books_count type="integer">85</books_count>
<ratings_count type="integer">156992</ratings_count>
<text_reviews_count type="integer">8489</text_reviews_count>
<original_publication_year type="integer">2011</original_publication_year>
<original_publication_month type="integer" nil="true"/>
<original_publication_day type="integer" nil="true"/>
<average_rating>4.01</average_rating>
<best_book type="Book">
<id type="integer">12609433</id>
<title>The Power of Habit: Why We Do What We Do in Life and Business</title>
<author>
<id type="integer">5201530</id>
<name>Charles Duhigg</name>
</author>
<image_url>https://images.gr-assets.com/books/1366758683m/12609433.jpg</image_url>
<small_image_url>https://images.gr-assets.com/books/1366758683s/12609433.jpg</small_image_url>
</best_book>
</work>
<results>
Here is the clarity of structure <imagelink> of structure XML file for more clarity.
2- Results.class 模型:
@Root (name = "results", strict = false)
public class Results {
@ElementList (name = "work", inline = true)
public List<Work> works;
public Results() {
}
public Results(List<Work> works) {
this.works = works;
}
public List<Work> getWorks() {
return works;
}
public void setWorks(List<Work> works) {
this.works = works;
}
}
2- Work.class 模型:
@Root(name = "work", strict = false)
public class Work {
@Path("best_book")
@Element(name = "id")
private int id;
@Path("best_book")
@Element (name = "title")
private String title;
@Path("best_book/author")
@Element(name = "name")
private String author;
@Path("best_book")
@Element (name = "image_url")
private String image;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
最佳答案
我找到了答案。在 Result.class 中,只需更改 @ElementList() 参数。这是解决方案:
错误-
@ElementList(name = "work", inline = true)
public List<Work> works;
解决方案-
@ElementList(inline = true, required = false)
public List<Work> works;
每当发生错误时,只需记住@ElementList() 中的两件事
1- inline=true
2- required=false
example : @ElementList(inline = true, required = false)
关于android - 如何解决org.simpleframework.xml.core.ValueRequiredException : Unable to satisfy @org. simpleframework.xml.ElementList(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42359010/
我从一个 Xml 文件中有这部分: image1.jpg image2.jpg image3.jpg 我知道我可以用以下方法解析它: @ElementList(entry = "image", inl
我在这个解析上挣扎了几个小时,所以我想也许你会有见解。我得到了这个 XML 结构: ... true
我正在尝试通过改进来解析 XML,但我被困在 ElementList 中。 我的 XML 看起来像这样: tue wed thu
我的问题很简单,但我什么也找不到。 我有一个列表类和一个用于 XML 序列化的入口类: @Root(name = "entries") public class List { @Element
我想向 ElementList 元素添加一个属性(带有 @Path 注释)...但它似乎不可行? 我想要这个: 但只能做到这一点: 下面的代码给了我一个
这是我想用 SimpleFramework 反序列化的 XML 片段: 23 blargh value 1 value 2 yet another value m
我正在使用 SimpleXML 框架来解析 Android 应用程序中的 xml。我在正确解析 @ElementList 时遇到问题。 XML fragment :
我正在尝试解析一些播客 xml 提要,但无法获取所有类别和其他具有相同名称的多个字段。 供稿示例:http://demo3984434.mockable.io/cast P
我的一个类中有以下代码: @Text(required=false) @ElementListUnion({ @ElementList(required = false, inline = t
我有一个具有映射类型属性的对象,但我希望将此映射序列化为列表,仅包含此映射的值。 我可以通过其他方式来做到这一点(例如,通过使 map transient ,添加几个返回 map 值的 setter/
我得到了错误 Android Magento Soap Api org.simpleframework.xml.core.PersistenceException: Element 'result'
我想使用 SimpleXML 将不同的 XML 序列化数据集反序列化为一个类(不同时) . 所有数据集的根类均为 ,但是不同的子类。有些有一个元素 , 的其他多个元素。 相同。这是我当前使用的
我正在尝试使用 SimpleXML 解析看起来像这样的 XML 响应。它与简单 xml 教程页面中显示的示例非常相似 http://simple.sourceforge.net/download/st
我有这个代码: @ElementList(name = "Telefono") @Namespace(reference = "efactura") protected List telefono;
在使用 SimpleXml 生成 XML 文件时,我遇到了充满挑战的问题。 我想通过以下方式进行动态xml输出。 ... ... ... ... 问题是如何使用 SimpleXMl
我似乎无法深入了解 - 非常感谢任何帮助! 我在 android v10 上使用 simple-xml-2.3.2.jar 所以我有这个 xml (kml): Admissions 60.59
我正在尝试使用 Retrofit 从 URL 获取书籍 xml 数据。但是当应用程序运行时,它显示错误。我是新来的所以请帮助我。这是错误信息: 02-20 23:06:37.943 23835
我是一名优秀的程序员,十分优秀!