将图像URL从JSON获取到数组中 [英] Get Image URLs from JSON into an Array

查看:104
本文介绍了将图像URL从JSON获取到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android的新手,我想弄清楚如何将Instagram JSON中的缩略图和标准分辨率照片的图像URL放入数组中,以便随后我可以使用Picasso下载图像并将其放入网格视图.

I'm new to Android and I'm trying to figure out how to get the image urls for thumbnails and standard resolution photos from Instagram JSON into arrays so that I can then use Picasso to download the images and put them into a grid view.

这是JSON.

{
  "pagination":  {
    "next_url": "https://api.instagram.com/v1/users/1373666362/media/recent?access_token=25320296.1fb234f.b797e861c2494059b6584ac9749208fe&count=2&max_id=791341826737262101_1373666362",
    "next_max_id": "791341826737262101_1373666362"
  },
  "meta":  {
    "code": 200
  },
  "data":  [
     {
      "attribution": null,
      "tags":  [
        "kystatefair"
      ],
      "type": "image",
      "location": null,
      "comments":  {
        "count": 0,
        "data":  []
      },
      "filter": "Amaro",
      "created_time": "1408648864",
      "link": "http://instagram.com/p/r-MuYWFU96/",
      "likes":  {
        "count": 5,
        "data":  [
           {
            "username": "tayworthington_",
            "profile_picture": "http://photos-g.ak.instagram.com/hphotos-ak-xaf1/10632550_835588266460870_765781001_a.jpg",
            "id": "24471760",
            "full_name": "τᎯϓιΘર"
          },
           {
            "username": "renee_laurent",
            "profile_picture": "http://images.ak.instagram.com/profiles/profile_407687505_75sq_1397913189.jpg",
            "id": "407687505",
            "full_name": "Renee Laurent"
          },
           {
            "username": "kystatefair",
            "profile_picture": "http://images.ak.instagram.com/profiles/profile_381460857_75sq_1396983015.jpg",
            "id": "381460857",
            "full_name": "kystatefair"
          },
           {
            "username": "jennaharrod1",
            "profile_picture": "http://photos-b.ak.instagram.com/hphotos-ak-xfa1/10665605_1495839117327497_809128971_a.jpg",
            "id": "18591399",
            "full_name": "Jenna Harrod"
          }
        ]
      },
      "images":  {
        "low_resolution":  {
          "url": "http://scontent-a.cdninstagram.com/hphotos-xaf1/t51.2885-15/10598650_352432021574566_306460147_a.jpg",
          "width": 306,
          "height": 306
        },
        "thumbnail":  {
          "url": "http://scontent-a.cdninstagram.com/hphotos-xaf1/t51.2885-15/10598650_352432021574566_306460147_s.jpg",
          "width": 150,
          "height": 150
        },
        "standard_resolution":  {
          "url": "http://scontent-a.cdninstagram.com/hphotos-xaf1/t51.2885-15/10598650_352432021574566_306460147_n.jpg",
          "width": 640,
          "height": 640
        }
      },
      "users_in_photo":  [],
      "caption":  {
        "created_time": "1408648864",
        "text": "Congratulations to The Lindsey Family for winning the Gospel Quartet competition! #kystatefair",
        "from":  {
          "username": "kyfarmbureau",
          "profile_picture": "http://photos-b.ak.instagram.com/hphotos-ak-xpf1/10349740_650479825030913_1755233568_a.jpg",
          "id": "1373666362",
          "full_name": "Kentucky Farm Bureau"
        },
        "id": "792126548887293629"
      },
      "user_has_liked": false,
      "id": "792126548258148218_1373666362",
      "user":  {
        "username": "kyfarmbureau",
        "website": "",
        "profile_picture": "http://photos-b.ak.instagram.com/hphotos-ak-xpf1/10349740_650479825030913_1755233568_a.jpg",
        "full_name": "Kentucky Farm Bureau",
        "bio": "",
        "id": "1373666362"
      }
    },
     {
      "attribution": null,
      "tags":  [
        "kfbmtc"
      ],
      "type": "image",
      "location": null,
      "comments":  {
        "count": 0,
        "data":  []
      },
      "filter": "Normal",
      "created_time": "1408555318",
      "link": "http://instagram.com/p/r7aTLelU4V/",
      "likes":  {
        "count": 4,
        "data":  [
           {
            "username": "corkey_cole",
            "profile_picture": "http://photos-e.ak.instagram.com/hphotos-ak-xaf1/10598220_490230854445140_2139881142_a.jpg",
            "id": "324166968",
            "full_name": "corkey_cole"
          },
           {
            "username": "renee_laurent",
            "profile_picture": "http://images.ak.instagram.com/profiles/profile_407687505_75sq_1397913189.jpg",
            "id": "407687505",
            "full_name": "Renee Laurent"
          },
           {
            "username": "silveradomafia04",
            "profile_picture": "http://photos-e.ak.instagram.com/hphotos-ak-xfa1/914483_1500860143488988_1771984176_a.jpg",
            "id": "1006562558",
            "full_name": "Gideon Bailey"
          },
           {
            "username": "sharelouisville",
            "profile_picture": "http://images.ak.instagram.com/profiles/profile_1302605134_75sq_1399019203.jpg",
            "id": "1302605134",
            "full_name": "Share Louisville"
          }
        ]
      },
      "images":  {
        "low_resolution":  {
          "url": "http://scontent-a.cdninstagram.com/hphotos-xaf1/t51.2885-15/10598436_1456586981280578_133918080_a.jpg",
          "width": 306,
          "height": 306
        },
        "thumbnail":  {
          "url": "http://scontent-a.cdninstagram.com/hphotos-xaf1/t51.2885-15/10598436_1456586981280578_133918080_s.jpg",
          "width": 150,
          "height": 150
        },
        "standard_resolution":  {
          "url": "http://scontent-a.cdninstagram.com/hphotos-xaf1/t51.2885-15/10598436_1456586981280578_133918080_n.jpg",
          "width": 640,
          "height": 640
        }
      },
      "users_in_photo":  [],
      "caption":  {
        "created_time": "1408555318",
        "text": "Media is starting to crowd around for #kfbmtc",
        "from":  {
          "username": "kyfarmbureau",
          "profile_picture": "http://photos-b.ak.instagram.com/hphotos-ak-xpf1/10349740_650479825030913_1755233568_a.jpg",
          "id": "1373666362",
          "full_name": "Kentucky Farm Bureau"
        },
        "id": "791341827391573199"
      },
      "user_has_liked": false,
      "id": "791341826737262101_1373666362",
      "user":  {
        "username": "kyfarmbureau",
        "website": "",
        "profile_picture": "http://photos-b.ak.instagram.com/hphotos-ak-xpf1/10349740_650479825030913_1755233568_a.jpg",
        "full_name": "Kentucky Farm Bureau",
        "bio": "",
        "id": "1373666362"
      }
    }
  ]
}

推荐答案

您必须首先处理JSON.例如:

You have to process the JSON first. For example:

// follow your JSON heirarchy!
JSONObject jsonObj = new JSONObject(jsonStr);
JSONObject data = jsonObj.getJSONObject("data");
JSONObject images = jsonObj.getJSONObject("images");
JSONObject lowRes = jsonObj.getJSONObject("low_resolution");
String url = lowRes.getString("url");

现在您有了网址,然后调用Picasso ....

Now you have the url, then invoke Picasso ....

Picasso.with(context).load(url).into(imageView);

这篇关于将图像URL从JSON获取到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆