- 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 时都会收到 ValueRequiredException: Unable to satisfy @org.simpleframew
谁能告诉我为什么我的解串器不工作? Main.java try { Serializer serializer = new Persister(); Asset
我正在集成 SimpleXml 反序列化,但每次都会出现异常。不知 Prop 体原因是什么。请检查此问题下提供的详细信息。提前致谢。 下面是模型类。 import java.util.ArrayLis
我正在尝试为 Android 编写一个简单的 RSS 阅读器应用程序。我使用 Retrofit 与 SimpleXMLConverter 进行网络通信,以从 XML 填充 POJO。这是我的 REST
我正在尝试使用 Retrofit 从 URL 获取书籍 xml 数据。但是当应用程序运行时,它显示错误。我是新来的所以请帮助我。这是错误信息: 02-20 23:06:37.943 23835
我是一名优秀的程序员,十分优秀!