处理具有各种尺寸JSON的多个图像

时间:2017-03-25 01:02:45

标签: ios json

"pictures": {
      "sizes": [
        {
          "width": 100,
          "height": 75,
          "link": "https://i.vimeocdn.com/video/566955426_100x75.jpg?r=pad",
          "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_100x75.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
        },
        {
          "width": 200,
          "height": 150,
          "link": "https://i.vimeocdn.com/video/566955426_200x150.jpg?r=pad",
          "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_200x150.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
        },
        {
          "width": 295,
          "height": 166,
          "link": "https://i.vimeocdn.com/video/566955426_295x166.jpg?r=pad",
          "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_295x166.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
        },
        {
          "width": 640,
          "height": 360,
          "link": "https://i.vimeocdn.com/video/566955426_640x360.jpg?r=pad",
          "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_640x360.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
        },
        {
          "width": 960,
          "height": 540,
          "link": "https://i.vimeocdn.com/video/566955426_960x540.jpg?r=pad",
          "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_960x540.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
        },
        {
          "width": 1280,
          "height": 720,
          "link": "https://i.vimeocdn.com/video/566955426_1280x720.jpg?r=pad",
          "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_1280x720.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
        }
      ]
    },

我正在开发一款ios应用。 这是我从Vimeo API处理的JSON,我想知道处理这些各种图像的正确方法是什么。我想抓住一个高度为540的那个,但在某些情况下,高度可能是541,或其他。另外如果没有高度为540的图像,我应该默认抓取最后一张图像吗?处理这个问题的正确方法是什么?我是否应该尝试抓住倒数第二个图像(大多数时候是高度为540的图像)并且如果只有一个图像抓住那个图像?从生产的角度来看,这种情况通常如何处理?非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

你的逻辑取决于你。迭代图像列表,找到正好是540的图像。如果不存在,则由您决定使用什么。您可以使用最接近540的那个(根据您的需要更大或更小)。挑选下一个更大的可能是最好的。通常情况下,将较大的图像设置得比试图显示较大的较小图像要小一些。