【发布时间】:2016-09-25 15:01:04
【问题描述】:
我正在尝试从此 api 获取数据:http://www.omdbapi.com/ 我正在使用 Retrofit 2 并为第一个 json 创建了一个 pojo。我很好奇的是如何在数据不可用时将我的 pojo 转换为第二个。
当有数据可用时,返回这个json:
http://www.omdbapi.com/?t=Suits
{
Title: "Suits",
Year: "2011–",
Rated: "TV-14",
Released: "23 Jun 2011",
Runtime: "44 min",
Genre: "Comedy, Drama",
Director: "N/A",
Writer: "Aaron Korsh",
Actors: "Gabriel Macht, Patrick J. Adams, Rick Hoffman, Meghan Markle",
Plot: "On the run from a drug deal gone bad, Mike Ross, a brilliant college-dropout, finds himself a job working with Harvey Specter, one of New York City's best lawyers.",
Language: "English",
Country: "USA",
Awards: "7 nominations.",
Poster: "http://ia.media-imdb.com/images/M/MV5BMTk1MjYzOTU2Nl5BMl5BanBnXkFtZTgwMzAxMTg5MTE@._V1_SX300.jpg",
Metascore: "N/A",
imdbRating: "8.7",
imdbVotes: "244,979",
imdbID: "tt1632701",
Type: "series",
totalSeasons: "6",
Response: "True"
}
当没有可用数据时,返回这个json:
http://www.omdbapi.com/?t=asdasdas
{
Response: "False",
Error: "Movie not found!"
}
【问题讨论】: