如何将网站视频列表的JSON代码转换为PHP数组以使用foreach循环?
Convert JSON Video List to PHP Array for
foreach Looping Hey there! Converting your JSON video list into a PHP array is super simple, and I'll show you exactly how to do it—plus how to loop through those video URLs with foreach to display them on your site.
Step 1: Decode the JSON into a PHP Array
PHP has a built-in function json_decode() that handles this perfectly. Pass true as the second argument to get an associative array instead of an object, which makes it easier to work with in foreach loops.
First, here's your original JSON (formatted for clarity):
{ "results": [ { "TCA_ANALYZING": [ "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/10120_f1.mp4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010001.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010001.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010002.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010002.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010014.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010014.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010111.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010111.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010112.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010112.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010113.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010113.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010114.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010114.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010115.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010115.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010116.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010116.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010117.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010117.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010118.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010118.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010119.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010119.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010120.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010120.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010121.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010121.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010122.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010122.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010123.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010124.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010124.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH020123.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAA0005.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAA0005.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAB0006.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAB0006.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAC0007.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAC0007.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAD0008.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAD0008.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAE0009.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAE0009.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAF0010.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAF0010.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAG0011.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAG0011.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAH0012.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAH0012.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAI0013.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAI0013.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010001.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010002.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010014.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010111.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010112.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010113.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010114.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010115.LRV", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GL010116.LRV" ] } ] }
Step 2: PHP Code to Convert and Loop Through the URLs
Here's the full PHP code snippet. I've included a check to make sure the JSON decodes correctly, plus an example that filters for only MP4 files (since your list includes THM and LRV files which aren't full videos):
<?php // Your JSON string (you could also load this from a file or API endpoint) $jsonString = '{ "results": [ { "TCA_ANALYZING": [ "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/10120_f1.mp4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010001.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010001.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010002.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010002.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010014.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010014.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010111.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010111.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010112.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010112.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010113.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010113.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010114.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010114.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010115.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010115.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010116.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010116.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010117.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010117.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010118.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010118.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010119.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010119.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010120.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010120.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010121.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010121.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010122.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010122.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010123.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010124.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH010124.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GH020123.THM", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAA0005.MP4", "https://storage.googleapis.com/gypsoid/GOPRO/GoPRO_1/100GOPRO/GHAA0005.THM", "https
相关产品推荐
相关产品推荐

