【发布时间】:2018-07-17 12:55:29
【问题描述】:
我的应用目前从网站中提取一些 API 数据。我需要它来显示 RecyclerView 列表中的元素。
API 数据是这样的:
<work>
<id type="integer">54397325</id>
<books_count type="integer">6</books_count>
<ratings_count type="integer">21</ratings_count>
<text_reviews_count type="integer">2</text_reviews_count>
<original_publication_year type="integer" nil="true"/>
<original_publication_month type="integer" nil="true"/>
<original_publication_day type="integer" nil="true"/>
<average_rating>4.10</average_rating>
<best_book type="Book">
<id type="integer">33584556</id>
<title>
Head First Android Development: A Brain-Friendly Guide
</title>
<author>
<id type="integer">773952</id>
<name>Dawn Griffiths</name>
</author>
<image_url>
https://images.gr-assets.com/books/1492905802m/33584556.jpg
</image_url>
<small_image_url>
https://images.gr-assets.com/books/1492905802s/33584556.jpg
</small_image_url>
</best_book>
</work>
我需要书名、作者和图片 URL 才能在 RecyclerView 中列出它们。
【问题讨论】:
-
您是否使用 Retrofit 进行 API 调用?
-
检查此链接以解析 xml tutorialspoint.com/android/android_xml_parsers.htm
-
@GiulioPettenuzzo 在您提供的链接中,他们使用了
InputStream is = getAssets().open("file.xml");。如何更改它以便从 API 请求中读取 XML? -
你读过这个吗? Google Documentation
-
我发布一个答案,向您展示如何在 InputStream 中转换字符串,假设您的 xml 是字符串格式
标签: java android xml-parsing