首页 > 解决方案 > 如何仅从 android 中的网页 url 获取图像

问题描述

我正在使用 google Fact Check API 制作一个应用程序,响应 json 是这样的

{
  "claims": [
    {
      "text": "“President El-Sisi confirmed Egypt's unwavering strategic position on Libya, which aimed at restoring stability in the country, preserving its national institutions, and preventing further deterioration in Libya’s security situation via curbing illegal foreign interference in the Libyan issue.”",
      "claimant": "Abdel-Fattah al-Sisi",
      "claimDate": "2020-07-24T00:00:00Z",
      "claimReview": [
        {
          "publisher": {
            "name": "POLYGRAPH.info",
            "site": "polygraph.info"
          },
          "url": "https://www.polygraph.info/a/egypt-libya-sisi-intervention/30745850.html",
          "title": "Egypt's al-Sisi Told Trump Foreign Interference in Libya is Bad – Just as his Parliament Authorized him to Intervene",
          "reviewDate": "2020-07-24T00:00:00Z",
          "textualRating": "Misleading",
          "languageCode": "en"
        }
      ]
    }
  ],
  "nextPageToken": "CAE"
}

我想知道如何获取 urls 图像并像这个 图像一样显示它

我似乎无法弄清楚如何获取图像,因为在 JSON 中只有网页的 url。

编辑:- 这是我使用 GSON 存储值的代码

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
                (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {

                        Log.i("response",response.toString());
                        Search search = gson.fromJson(response.toString(),Search.class);
                        Log.i("response",search.toString());
                        textView.setText("Claim:- "+search.claims.get(0).text+"\nFactual Rating:-"+search.claims.get(0).claimReview.get(0).textualRating);

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.i("response",error.toString());// TODO: Handle error

                    }
                });

标签: androidjson

解决方案


如果您知道确切的网站,则可以使用网络抓取工具。看看你怎么能在这里做到。


推荐阅读