我从news api得到一个json响应,如下所示
status": "ok",
"totalResults": 38,
"articles": [{
"author": "Zoe Christen Jones",
"title": "Skylar Mack, American teen jailed for violating quarantine in Cayman
Islands, gets reduced sentence - CBS News",
"description": "Skylar Mack, ..."
}]
通常我会创建一些类来表示它的每个响应
data class NewsResponse(
@SerializedName("status") var status: String? = null,
@SerializedName("totalResult") var total: String? = null,
@SerializedName("articles") var articles: List<Articles> = emptyList()
)
data class Articles(
@SerializedName("author") var author: String? = null,
@SerializedName("title") var title: String? = null,
@SerializedName("description") var url: String? = null)
但是,假设我只是想 articles
从根响应,注解如下
data class NewsResponse(
@SerializedName("articles") var articles: List<Articles> = emptyList()
)
这是一个好的做法,只是ommit不必要的回应,我不想?在这种情况下,我不想抓住 status
以及 totalResponse
.
暂无答案!
目前还没有任何答案,快来回答吧!