Java 在Android中为Goodreads API响应创建POJO类
我想在Android中使用simplexml和改型2创建POJO类,但我一直坚持为搜索API创建模型类 下面是一个xml响应示例,我想将其映射到POJO类Java 在Android中为Goodreads API响应创建POJO类,java,android,xml,pojo,Java,Android,Xml,Pojo,我想在Android中使用simplexml和改型2创建POJO类,但我一直坚持为搜索API创建模型类 下面是一个xml响应示例,我想将其映射到POJO类 <GoodreadsResponse> <Request> <authentication>true</authentication> <key><![CDATA[]]></key> <method><
<GoodreadsResponse>
<Request>
<authentication>true</authentication>
<key><![CDATA[]]></key>
<method><![CDATA[search_search]]></method>
</Request>
<search>
<query>...</query>
<results-start>1</results-start>
<results-end>20</results-end>
<total-results>491</total-results>
<source>Goodreads</source>
<query-time-seconds>0.14</query-time-seconds>
<results>
<work>
<id type="integer">2422333</id>
<books_count type="integer">214</books_count>
<ratings_count type="integer">810505</ratings_count>
<text_reviews_count type="integer">36595</text_reviews_count>
<original_publication_year type="integer">1985</original_publication_year>
<original_publication_month type="integer" nil="true" />
<original_publication_day type="integer" nil="true" />
<average_rating>4.29</average_rating>
<best_book type="Book">
<id type="integer">375802</id>
<title>Ender's Game (Ender's Saga, #1)</title>
<author>
<id type="integer">589</id>
<name>Orson Scott Card</name>
</author>
<image_url>https://images.gr-assets.com/books/1408303130m/375802.jpg</image_url>
<small_image_url>https://images.gr-assets.com/books/1408303130s/375802.jpg</small_image_url>
</best_book>
</work>
<work>
<id type="integer">938064</id>
<books_count type="integer">54</books_count>
<ratings_count type="integer">69233</ratings_count>
<text_reviews_count type="integer">586</text_reviews_count>
<original_publication_year type="integer">1984</original_publication_year>
<original_publication_month type="integer">12</original_publication_month>
<original_publication_day type="integer" nil="true" />
<average_rating>4.16</average_rating>
<best_book type="Book">
<id type="integer">44687</id>
<title>Enchanters' End Game (The Belgariad, #5)</title>
<author>
<id type="integer">8732</id>
<name>David Eddings</name>
</author>
<image_url>https://images.gr-assets.com/books/1217735909m/44687.jpg</image_url>
<small_image_url>https://images.gr-assets.com/books/1217735909s/44687.jpg</small_image_url>
</best_book>
</work>
</results>
</search>
</GoodreadsResponse>
真的
...
1.
20
491
古德雷兹
0.14
2422333
214
810505
36595
1985
4.29
375802
安德的游戏(安德的传奇,#1)
589
奥森·斯科特·卡德
https://images.gr-assets.com/books/1408303130m/375802.jpg
https://images.gr-assets.com/books/1408303130s/375802.jpg
938064
54
69233
586
1984
12
4.16
44687
魔术师的最后一局(贝尔加里亚人,第5局)
8732
大卫·艾丁斯
https://images.gr-assets.com/books/1217735909m/44687.jpg
https://images.gr-assets.com/books/1217735909s/44687.jpg
到目前为止,我的模型课不起作用。在改造中,我得到了一个响应,但它没有映射到创建的模型:
@Root(strict=false)
public class GoodreadsResponse {
@Element(name = "work")
public static class Work {
@Element
int id;
}
@Element(name = "search")
public static class Search {
@Element
Results results;
}
@Element(name = "results")
public static class Results {
@ElementList(name = "results", entry = "work")
ArrayList<Work> results;
}
}
@Root(strict=false)
公共类商品响应{
@元素(name=“work”)
公共静态课堂工作{
@元素
int-id;
}
@元素(name=“search”)
公共静态类搜索{
@元素
结果;
}
@元素(name=“results”)
公共静态类结果{
@元素列表(name=“results”,entry=“work”)
ArrayList结果;
}
}
我只对元素工作中的书籍列表和每本书的图像url感兴趣
我非常感谢你的帮助