问题
i can't seem to get value from only element with CDATA
block, only return empty value, hope you guys can help, this is my xml data:
<response>
<error>
<![CDATA[OK]]>
</error>
<limit>10</limit>
<offset>0</offset>
<number_of_page_results>10</number_of_page_results>
<number_of_total_results>481312</number_of_total_results>
<status_code>1</status_code>
<results>
<issue>
<aliases/>
<api_detail_url>
<![CDATA[http://comicvine.gamespot.com/api/issue/4000-6/]]>
</api_detail_url>
<cover_date>
<![CDATA[1952-10-01]]>
</cover_date>
<date_added>2008-06-06 11:10:16</date_added>
<date_last_updated>2015-07-11 12:08:20</date_last_updated>
<deck/>
<description>
<![CDATA[<p>The horrors of:</p><p>- Lost race!</p><p>- The man germ!</p><p>- Man in the hood!</p><p>- The things!</p><p>-Stories behind the stars, featuring the legendary battle between Hercules, Hydra and Iolaus!</p><p>Plus, two page long prose-stories.</p>]]>
</description>
<has_staff_review></has_staff_review>
<id>6</id>
<image>
<icon_url>
<![CDATA[http://static1.comicvine.com/uploads/square_avatar/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</icon_url>
<medium_url>
<![CDATA[http://static2.comicvine.com/uploads/scale_medium/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</medium_url>
<screen_url>
<![CDATA[http://static3.comicvine.com/uploads/screen_medium/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</screen_url>
<small_url>
<![CDATA[http://static4.comicvine.com/uploads/scale_small/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</small_url>
<super_url>
<![CDATA[http://static5.comicvine.com/uploads/scale_large/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</super_url>
<thumb_url>
<![CDATA[http://static6.comicvine.com/uploads/scale_avatar/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</thumb_url>
<tiny_url>
<![CDATA[http://static7.comicvine.com/uploads/square_mini/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</tiny_url>
</image>
<issue_number>13</issue_number>
<name>
<![CDATA[The Lost Race]]>
</name>
<site_detail_url>
<![CDATA[http://comicvine.gamespot.com/chamber-of-chills-magazine-13-the-lost-race/4000-6/]]>
</site_detail_url>
<store_date/>
<volume>
<api_detail_url>
<![CDATA[http://comicvine.gamespot.com/api/volume/4050-1487/]]>
</api_detail_url>
<id>1487</id>
<name>
<![CDATA[Chamber of Chills Magazine]]>
</name>
<site_detail_url>
<![CDATA[http://comicvine.gamespot.com/chamber-of-chills-magazine/4050-1487/]]>
</site_detail_url>
</volume>
</issue>
</results>
<version>1.0</version>
</response>
with my 2 model class:
@Root(name = "response", strict = false)
public class IssueWrapper extends BaseObject {
@ElementList(name = "results")
List<Issue> issues;
public List<Issue> getIssues() {
return issues;
}
}
@Element(name = "issue")
public class Issue extends BaseObject {
@Element(name = "id")
int id;
@Element(name = "date_added")
String dateAdded;
@Element(name = "description", data = true, required = true)
String description;
@Element(name = "issue_number")
int issueNumber;
public String getDateAdded() {
return dateAdded;
}
public int getIssueNumber() {
return issueNumber;
}
}
Logcat output:
Caused by: org.simpleframework.xml.core.ValueRequiredException: Empty value for @org.simpleframework.xml.Element(data=true, name=description, required=true, type=void) on field 'description' public java.lang.String truongan.android.comicvineapiapp.model.Issue.description in class truongan.android.comicvineapiapp.model.Issue at line 2
回答1:
Use
@Element(data = true)
来源:https://stackoverflow.com/questions/37361355/cant-parse-xml-with-cdata-block-using-simplexml-and-retrofit