0

I'm trying to get thumbnail_url form the following JSON

    {
  "uuid": "00012710-4b65-0131-ffe6-22000a499ea4",
  "camera_uuid": "98373a20-79ee-0130-3e42-1231390fcc11",
  "created_at": "2013-12-20T05:25:02.000Z",
  "percent_complete": 100,
  "short_code": "KKtB4Q",
  "metadata": {
  },
  "state": "published",
  "recorded_from": "http://singwho.com",
  "publish_type": null,
  "formats": [
    {
      "name": "720p",
      "width": 1280,
      "height": 720,
      "video_url": "https://cameratag.com/videos/00012710-4b65-0131-ffe6-22000a499ea4/720p/mp4.mp4",
      "flv_url": null,
      "flv_stream": null,
      "mp4_url": "https://cameratag.com/videos/00012710-4b65-0131-ffe6-22000a499ea4/720p/mp4.mp4",
      "mp4_stream": "rtmp://sa0xpxq1vz1ri.cloudfront.net/cfx/st&mp4:98373a20-79ee-0130-3e42-1231390fcc11/00012710-4b65-0131-ffe6-22000a499ea4_720p.mp4?Expires=1436913071&Signature=NppwMddejKbM2JMYrjsUUC5TJN0YfbgOox6sBKwO1YcftAaspf25ByG8drEG4zM-pTD6mST71YtBb3pQ5JzhHM33B6JQv0BsZvjGHarA7kVq9b6GG27wY5N5F6Sy79l5GNO3k9-Sh4MRy6fABZEDQUxd8TZ1HD7Usj2FlPYXxWXZmWQlo~43YKRnium7dcEzh-RRXbXfNQarfz1ju~OXI4J9ug1DRmHVtqV0F32cEDdCSCVy5Tyokf7IgO5SXATkuIkRtt52TdInFXmWmLbGfopDtKgua8NZXPaDbK35ra7AX2DuQE3iKTeX5oCWgVCPCAUz1PenLtK8rOYhTyYgJg__&Key-Pair-Id=APKAIYEVFIMHKY7YWGKA",
      "webm_url": "https://cameratag.com/videos/00012710-4b65-0131-ffe6-22000a499ea4/720p/webm.webm",
      "webm_stream": "rtmp://sa0xpxq1vz1ri.cloudfront.net/cfx/st&webm:98373a20-79ee-0130-3e42-1231390fcc11/00012710-4b65-0131-ffe6-22000a499ea4_720p.webm?Expires=1436913071&Signature=Qc-gjpwSHp3QmXzoiLuAMy11ReUHyLvRuuaszBYRT~GEzp~wl-TTZ-sGqo-XBlJlxH-54LmzXPryygS8ZCwdQQs0~5le69YXlL8RONl7kaLwmLSKlSE0PJlGzJoUW8kqO1mZxIfvrcmpYPdpCukm5J6eTv2U0rWCzAGfAeSiT7kUUc-9uGxLjjeOLIXVKebyYYhjT3wC-Gp5jd4ODCq3JB-IAWpOCOcXxF7oCuF-ag5WznaAeasW200M4yuYHvuDmu~dz~r52NcykeldzQ9Wq4laRuxaLRYaGZpB3y7og31RoWo75bomoT2vOO2rO-4~pz1tcfoYsg05T14er62KOA__&Key-Pair-Id=APKAIYEVFIMHKY7YWGKA",
      "thumbnail_url": "https://cameratag.com/videos/00012710-4b65-0131-ffe6-22000a499ea4/720p/thumb.png",
      "small_thumbnail_url": "https://cameratag.com/videos/00012710-4b65-0131-ffe6-22000a499ea4/720p/small_thumb.png",
      "state": "COMPLETED",
      "completed_at": "2013-12-20T05:30:12.000Z",
      "length": 195
    }
  ],
  "plays": 0
}

This is how decode the JSON, I'm able to get 'uuid'

$raw = file_get_contents('php://input');
        $json = json_decode($raw, true);

I tried with

foreach ($json->formats as $format) {
        $url = $format["thumbnail_url"];
    }

and

$url = $json->formats[0]->thumbnail_url

and

$url = $json['formats']['thumbnail_url']

but I'm still unnable to get the right value. I'm I missing something?

0

1 Answer 1

2

You just about had its $url = $json['formats'][0]['thumbnail_url']

$json is a nested array. $json['formats'] is an array of objects, to get the first object use $json['formats'][0]

You can easily see what is in $json with var_export($json) or print_r($json)

Sign up to request clarification or add additional context in comments.

1 Comment

And analogous the foreach loop would look like foreach ($json['formats'] as $format) { - after all formats is an array, there could be more than one element ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.