【发布时间】:2019-03-20 16:35:54
【问题描述】:
{
"Query":"query",
"KMAQuery":"query",
"TotalCount":3,
"Data":[{"CollName":"kmdb_new",
"TotalCount":3,
"Count":3,
"Result":[{"title":"sampletitle",
"director":[{"directorNm":"name1","directorId":"00004544"}],
"nation":"nation1",
"company":"company1",
"genre":"genre1",
"kmdbUrl":"http://www.kmdb.or.kr/vod/vod_basic.asp?nation=K&p_dataid=01040",
"rating":[{"ratingMain":"Y","ratingDate":"19640717","ratingNo":"","ratingGrade":"","releaseDate":"","runtime":""}]]}
这是我从 OKHttp 解析得到的 Json 数据。
其实有很多相同的Result 2~3。
我要解析键名“title”、“directorNm”、“nation”、“company”、“ratingGrade”并设置Model类。
如何将多个带有Gson的Json Object和Array解析成Model类?
我终于要在模型类中使用recyclerview了。
如果你告诉我如何解析“title”和“directorNm”,我可以休息一下。
作为参考,我正在使用 AsyncTask、OKHttp、Gson 等。
如果你不明白我的问题或需要代码,请评论!
我非常需要你的帮助。
【问题讨论】:
-
另外,我使用的是 AsyncTask。如何在 doInBackground 中解析并返回 onPostExecute?
-
@NileshRathod 我现在就试试!
-
@NileshRathod 我的 pojo 类是对的,但我不知道如何在 Android Activity 中将值设置为模型
-
你可以使用Gson github.com/google/gson