如何解码和存储此json文件中的图像?

时间:2017-11-18 23:05:32

标签: php json

我有一个json文件,如下所示:

ycell

等等。我必须下载所有项目并缓存每个资产中的图像。 下面是我在开始时尝试做的,但它似乎输出我NULL。你能帮帮我吗?

[
  {
    "skyGoUrl": "http://go.sky.com/vod/content/GOPCMOVIES/RSS/Movies/content/assetId/6ba3fb6afd03e310VgnVCM1000000b43150a________/videoId/d1bf901693832410VgnVCM1000000b43150a________/content/playSyndicate.do",
    "url": "http://skymovies.sky.com/parental-guidance/review",
    "reviewAuthor": "Tim Evans",
    "id": "8ad589013b496d9f013b4c0b684a4a5d",
    "cert": "U",
    "viewingWindow": {
      "startDate": "2013-12-27",
      "wayToWatch": "Sky Movies",
      "endDate": "2015-01-21"
    },
    "headline": "Parental Guidance",
    "cardImages": [
      {
        "url": "http://vodassets.s3-website-us-east-1.amazonaws.com/images/unscaled/2012/11/29/Parental-Guidance-VPA.jpg",
        "h": 1004,
        "w": 768
      },
      {
        "url": "http://vodassets.s3-website-us-east-1.amazonaws.com/images/unscaled/2013/07/15/LPA-Parental-guidance.jpg",
        "h": 748,
        "w": 1024
      },
      {
        "url": "http://vodassets.s3-website-us-east-1.amazonaws.com/images/unscaled/2012/11/29/Parental-Guidance-VPA-VPA-to-CP3.jpg",
        "h": 460,
        "w": 320
      },
      {
        "url": "http://vodassets.s3-website-us-east-1.amazonaws.com/images/unscaled/2012/11/29/Parental-Guidance-VPA-VPA-to-CP4.jpg",
        "h": 920,
        "w": 640
      },
      {
        "url": "http://vodassets.s3-website-us-east-1.amazonaws.com/images/unscaled/2013/07/15/LPA-Parental-guidance-LPA-to-LP3.jpg",
        "h": 300,
        "w": 480
      },
      {
        "url": "http://vodassets.s3-website-us-east-1.amazonaws.com/images/unscaled/2013/07/15/LPA-Parental-guidance-LPA-to-LP4.jpg",
        "h": 600,
        "w": 960
      },
      {
        "url": "http://vodassets.s3-website-us-east-1.amazonaws.com/images/unscaled/2012/11/29/Parental-Guidance-DI-DI-to-CW.jpg",
        "h": 720,
        "w": 1280
      }
    ]
    ],

1 个答案:

答案 0 :(得分:0)

您的JSON文件是一个数组,这意味着您需要获取项目,然后获取所需的密钥。在您的情况下,您将使用:

$allImages = $array[0]['cardImages'];

我希望我帮忙! -CM