【发布时间】:2016-05-11 15:22:20
【问题描述】:
我正在尝试从 dailymotion 获取视频网址。 我得到了 JSON 结果,并通过在线工具对其进行了有效测试,但是当我使用 js_decode 和 print_r 时,它会显示类似警告
<?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);
print_r($response);
?>
我想从 JSON 中获取视频质量和视频 url。
【问题讨论】:
-
在
explode之后检查您的$json格式是否正确?其次,你为什么用了两次file_get_contents? -
尝试获得
$content一次,只需json_decode($content, true);你将获得array然后你就可以玩了。我认为两次使用file_get_contents不是一个好方法。 -
谢谢它的工作。如何读取 json 值?
-
循环遍历结果数组,例如
$array = json_decode($json,true);foreach ($array as $key=>$value){ echo $key.'---'; print_r($value[0]['url']); echo '<br>'; }
标签: php json file-get-contents