改造模型对象

时间:2016-03-14 21:14:46

标签: android json retrofit2

我是Retrofit的新手。我需要为下面的JSON查询创建一个Parcelable模型对象,但似乎无法使其工作。鉴于下面的JSON中有两个id属性,我有点困惑。任何帮助都会很棒。

JSON查询

   {"id":83542,"page":1,"results":[{"id":"51910979760ee320eb020fc2","author":"Andres Gomez","content":"Interesting film with an exceptional cast, fantastic performances and characterizations. The story, though, is a bit difficult to follow and, in the end, seems to not have a real point.","url":"https://www.themoviedb.org/review/51910979760ee320eb020fc2"},{"id":"520a8d10760ee32c8718e6c2","author":"Travis Bell","content":"Cloud Atlas was a very well made movie but unlike most of the \"simultaneous stories that all come together at the end\" type of movies, this one just didn't. I'm still unclear as to the point of it all.\r\n\r\nAnother issue I had was a general feeling of goofiness. Sure, the Cavendish story was pure comedy but the rest of the stories just didn't feel serious enough to me.\r\n\r\nIt carried my attention for the 172 minutes well enough and it was entertaining. I just expected more of a pay off at the end.\r\n\r\nAll in all, it's definitely worth seeing but I still haven't made up my mind if I truly liked it or not. What did you think?","url":"https://www.themoviedb.org/review/520a8d10760ee32c8718e6c2"}],"total_pages":1,"total_results":2}

1 个答案:

答案 0 :(得分:0)

为json尝试以下模型类:

public class Example {
   int id;
   int page;
   List<Result> results = new ArrayList<Result>();
   int total_pages;
   int total_results;
}

public class Result {
   String id;
   String author;
   String content;
   String url;
}

如果您想将JSON转换为POJO',请使用jsonschema2pojo执行此操作。

希望这有帮助!