Page 1 of 1

Decode json file {cache_remote_file}

Posted: Wed Sep 29, 2021 8:17 pm
by andrewvideouk
Hi Guys.

I am trying to Decode json file using cache_remote_file plugin. I cant get my head round how to do this. This is my attempt and cant workout how to do this. Can please someone tell me what I am doing worng and how to it. Thank you.

Code: Select all

{capture assign=feed}{cache_remote_file url="https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&id=Duf5UUT......"}{/capture}


{foreach from=$feed|json_decode item=data}
           <p> title : {$data->items->snippet->title}  </p>
            <p> img : {$data->items->snippet->thumbnails->default->url}  </p>
      
{/foreach}

Code: Select all

{
  "kind": "youtube#videoListResponse",
  "etag": "9ZzDWJlUMjKGsGwGvtEREF_adhk",
  "items": [
    {
      "kind": "youtube#video",
      "etag": "L3XeWemLM2vSCJh_RkWQgIjUbs4",
      "id": "Duf5UUT4ESg",
      "snippet": {
        "publishedAt": "2021-07-21T16:39:22Z",
        "channelId": "UCEUfZ0aVKoC80RIAfvTBfDw",
        "title": "Sheffield Voices speaking out on issues of abuse at Firshill Sheffield",
        "description": "Sheffield Voices Self Advocacy group have been shocked and upset by reports of people with learning disabilities and Autism being restrained, not being given food and water, being ignored and not being protected from violence within the Assessment and Treatment Unit and have made a video so people know how we are feeling about this",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/Duf5UUT4ESg/default.jpg",
            "width": 120,
            "height": 90
          },
          ......................

Re: Decode json file {cache_remote_file}

Posted: Thu Sep 30, 2021 11:06 pm
by andrewvideouk
I was missing the [0] which I didn't know. I was so close. Now it working.

{foreach from=$feed|json_decode item=data}
<p> title : {$data[0]->snippet->title} </p>
<p> img : {$data[0]->snippet->thumbnails->default->url} </p>
{/foreach}

Re: Decode json file {cache_remote_file}

Posted: Sun Oct 03, 2021 9:08 am
by andrewvideouk
I thought I got that working. Do anyone how do this? Cheers

Re: Decode json file {cache_remote_file}

Posted: Mon Oct 04, 2021 9:52 am
by macyogi2
Hi,
I do not know the cache_remote_file plugin.
However, based on the JSON, I would suggest the following code:

Code: Select all

{capture assign=feed} ... {/capture}

{$feed = $feed|json_decode}
{foreach from=$feed->items item=item}

           <p> title : {$item->snippet->title}  </p>
            <p> img : {$item->snippet->thumbnails->default->url}  </p>
      
{/foreach}
best wishes

Re: Decode json file {cache_remote_file}

Posted: Thu Oct 07, 2021 1:39 am
by andrewvideouk
Thank you so much. That worked great.