使用文件获取内容的JSON到PHP数组不起作用

使用文件获取内容的JSON到PHP数组不起作用,php,json,file-get-contents,Php,Json,File Get Contents,我正在尝试从dailymotion获取视频URL。 我用在线工具测试了JSON结果和它的有效性,但当我使用js_decode&print_r时,它会显示类似于 使用数组\u键($array)您可以从数组中获取所有键,它将返回一个包含键的数组 <?php $content = file_get_contents("http://www.dailymotion.com/embed/video/x49oyt5"); $content = explode(',"qualities":', $

我正在尝试从dailymotion获取视频URL。 我用在线工具测试了JSON结果和它的有效性,但当我使用js_decode&print_r时,它会显示类似于

使用
数组\u键($array)
您可以从数组中获取所有键,它将返回一个包含键的数组

<?php

$content = file_get_contents("http://www.dailymotion.com/embed/video/x49oyt5");

$content = explode(',"qualities":', $content);

$json = explode(',"reporting":', $content[1]);

$json = $json[0];

$mycontent = file_get_contents($json);

$response = json_decode($mycontent, true);

$qualities = array_keys($response)

print_r($qualities);

?>

您正在对实际上已经是JSON的内容使用file\u get\u内容

已更新代码,已测试;)



分解后检查您的
$json
格式是否正确?其次,为什么要使用
file\u get\u contents
两次?尝试获取
$content
一次,然后只进行
json\u解码($content,true)
您将获得
阵列
,然后您就可以到处玩了。我认为使用
文件获取内容两次不是一个好方法。谢谢,它很管用。如何读取json值?循环生成的数组,例如,
$array=json\u decode($json,true)
foreach($key=>$value数组){echo$key.--';print_r($value[0]['url']);echo'
;}
谢谢这是一个大错误。那么,如何读取属性值,如240、380、480和url值?资源按其质量分组,因此您只需访问所需的质量密钥并循环访问资源。请编写一些工作代码以访问属性?谢谢
<?php

$content = file_get_contents("http://www.dailymotion.com/embed/video/x49oyt5");

$content = explode(',"qualities":', $content);

$json = explode(',"reporting":', $content[1]);

$json = $json[0];

$mycontent = file_get_contents($json);

$response = json_decode($mycontent, true);

$qualities = array_keys($response)

print_r($qualities);

?>
<?php

$content = file_get_contents("http://www.dailymotion.com/embed/video/x49oyt5");

$content = explode(',"qualities":', $content);

$json = explode(',"reporting":', $content[1]);

$json = $json[0];

$videos = json_decode($json,true);

//Cycle through the 1080 videos and print the video urls
foreach($videos[1080] as $video){
  printf("Video type:%s URL:%s\n", $video['type'], $video['url']);
}

//Cycle through the 720 videos and print the video urls
foreach($videos[720] as $video){
  printf("Video type:%s URL:%s\n", $video['type'], $video['url']);
}
?>