你好,我使用PixaBay API在我的应用程序中获取图像,我使用url https://pixabay.com/api/?key=My-KEY.I获得响应,如下所示,如何从下面的响应中生成POJO类。
{
"total":1261984,
"totalHits":500,
"hits":[
{
"id":5265194,
"pageURL":"https://pixabay.com/photos/lein-staudenlein-blue-flax-flower-5265194/",
"type":"photo",
"tags":"lein, staudenlein, blue flax",
"previewURL":"https://cdn.pixabay.com/photo/2020/06/06/04/20/lein-5265194_150.jpg",
"previewWidth":150,
"previewHeight":100,
"webformatURL":"https://pixabay.com/get/53e2d3464b5ba814f1dc8460962931771d3cdae5504c704c7c2e73d5964fc05e_640.jpg",
"webformatWidth":640,
"webformatHeight":427,
"largeImageURL":"https://pixabay.com/get/53e2d3464b5ba814f6da8c7dda7936781c37dde153526c4870267adc964cc75dbe_1280.jpg",
"imageWidth":6240,
"imageHeight":4160,
"imageSize":5132057,
"views":9106,
"downloads":8127,
"favorites":25,
"likes":77,
"comments":68,
"user_id":10327513,
"user":"NickyPe",
"userImageURL":"https://cdn.pixabay.com/user/2020/06/08/09-39-40-606_250x250.jpg"
},
{
"id":5255326,
"pageURL":"https://pixabay.com/photos/landscape-fantasy-sky-clouds-5255326/",
"type":"photo",
"tags":"landscape, fantasy, sky",
"previewURL":"https://cdn.pixabay.com/photo/2020/06/03/15/20/landscape-5255326_150.jpg",
"previewWidth":150,
"previewHeight":100,
"webformatURL":"https://pixabay.com/get/53e2d0464950aa14f1dc8460962931771d3cdae5504c704c7c2e73d5964fc05e_640.jpg",
"webformatWidth":640,
"webformatHeight":427,
"largeImageURL":"https://pixabay.com/get/53e2d0464950aa14f6da8c7dda7936781c37dde153526c4870267adc964cc75dbe_1280.jpg",
"imageWidth":7087,
"imageHeight":4724,
"imageSize":3912235,
"views":29283,
"downloads":24114,
"favorites":80,
"likes":174,
"comments":108,
"user_id":3764790,
"user":"enriquelopezgarre",
"userImageURL":"https://cdn.pixabay.com/user/2020/06/03/11-05-03-625_250x250.jpg"
}
]
} 在这里,我只想从上面的response.How获取预览URL,我可以为same.Someone制作POJO类,请帮助我,任何帮助都将不胜感激。
谢谢
发布于 2020-06-10 18:19:16
您可以使用此网站生成pojo类。这是链接http://www.jsonschema2pojo.org/
发布于 2020-06-10 18:20:47
做以下事情:
public class Pixabay{
public int total;
public int totalHits;
public List<Hits> hits;
// inner class Hits with all attributes
public class Hits{
public int id;
//..... and so on
}
}我希望你能拍到照片?你必须通过检查它们的值来正确地映射它们。
干杯!
发布于 2020-06-10 18:21:38
你的课就像
data class pixBit(val hints:List<pixBitList>)
data class pixBitList(val previewURL:String)将您的响应映射到第一个pojo类,通过访问映射数据中的提示列表,您可以获取每个previewUrl
https://stackoverflow.com/questions/62310092
复制相似问题