如何根据名称获取图像URL

时间:2017-11-01 10:30:33

标签: android android-recyclerview

我的JSON仅包含食物类别的名称,如下所示

[
{
    "cu_id": "2",
    "cuisine_type": "American"
},
{
    "cu_id": "24",
    "cuisine_type": "Sandwich"
},
{
    "cu_id": "17",
    "cuisine_type": "Seafood"
},
{
    "cu_id": "29",
    "cuisine_type": "Sports Bar"
},
{
    "cu_id": "5",
    "cuisine_type": "Steak"
},
{
    "cu_id": "20",
    "cuisine_type": "Sushi"
}
]

我想通过搜索“cuisine_type'”来自动从互联网上获取默认图片,如何做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以使用pixabay api它是一个免费的RESTful api,用于搜索和检索在Commons CC0下发布的免费图片和视频。

发送GET这样的请求:

https://pixabay.com/api/?key={ KEY }&q=query&image_type=photo

其中:

  • 密钥:创建帐户后获得的API密钥
  • q:您需要查询的查询对象
  • image_type:您需要什么样的数据(图片,视频)

返回的数据将是这样的:

{
"total": 4692,
"totalHits": 500,
"hits": [
    {
        "id": 195893,
        "pageURL": "https://pixabay.com/en/blossom-bloom-flower-yellow-close-195893/",
        "type": "photo",
        "tags": "blossom, bloom, flower",
        "previewURL": "https://static.pixabay.com/photo/2013/10/15/09/12/flower-195893_150.jpg"
        "previewWidth": 150,
        "previewHeight": 84,
        "webformatURL": "https://pixabay.com/get/35bbf209db8dc9f2fa36746403097ae226b796b9e13e39d2_640.jpg",
        "webformatWidth": 640,
        "webformatHeight": 360,
        "imageWidth": 4000,
        "imageHeight": 2250,
        "imageSize": 4731420,
        "views": 7671,
        "downloads": 6439,
        "favorites": 1,
        "likes": 5,
        "comments": 2,
        "user_id": 48777,
        "user": "Josch13",
        "userImageURL": "https://static.pixabay.com/user/2013/11/05/02-10-23-764_250x250.jpg",
    },
    {
        "id": 14724,
        ...
    },
    ...
]
}

有关详细信息,请访问此link