我正在制作一个需要显示视频的html页面。视频的URL可在jsondecode
输出中找到。这里有什么方法可以从JSON
输出中挑选片段并在我的html页面中使用它吗?我试过POST、GET和echo,但似乎都不起作用。
需要明确的是:我正试图将它从一个php文件转换为一个单独的HTML文件
JSON
响应位于函数中的一个单独文件中。
public function getURL(){
$server_url= ilObjPresentations2GoGUI::getServerUrl();
$secret_key= ilObjPresentations2GoGUI::getSecretKey();
$authorized_group= ilObjPresentations2GoGUI::getAuthorizedGroup();
$link_usable= ilObjPresentations2GoGUI::getLinkUsable();
$query = 'technology';
$date = new DateTime('NOW');
$ts = $date->format('Y-m-d'TH:i:s');
$interval = 'PT' . $this->link_usable . 'H';
$date->add(new DateInterval('PT' . $link_usable . 'H'));
$expired = $date->format('Y-m-d'TH:i:s');
$url = $server_url . '?action=search&query='. $query . '&group='. $authorized_group . '&ts=' . $ts . '&expired=' .$expired;
$token = ilObjPresentations2GoAPI::create($url,$secret_key);
$goodurl = $url . '&token=' . $token;
$json = file_get_contents($goodurl);
$the_data = json_decode($json, true);}
输出:
array(9) { ["schemaVersion"]=> string(3) "1.0" ["catalogueVersion"]=> string(14) "4.0.5651.20898" ["encoding"]=> string(5) "UTF-8" ["action"]=> string(6) "search" ["query"]=> string(10) "technology" ["page"]=> string(1) "1" ["pageCount"]=> string(1) "1" ["success"]=> string(4) "true" ["response"]=> array(3) { [0]=> array(10) { ["id"]=> string(6) "bWKUL2" ["title"]=> string(57) "Technology-Based Professional Learning and Support Models" ["date"]=> string(19) "2011-12-05T10:19:21" ["contributors"]=> string(0) "" ["thumbnailUrl"]=> string(409) "https://DEMO-FORMS.presentations2go.eu/P2G/plugins/mediaservice.aspx?
(这不是全部,但否则它将是半页)
您可以在html中使用JSON解码数组中的数据,只要这些文件的扩展名为.php或包含在php:中即可
<div><?php echo $the_data['title']; ?></div>
由于$the_data
数组在方法getURL()
中,因此可以返回$the_data
数组中的URL:
public function getURL() {
...
$the_data = json_decode($json, true);
return !empty($the_data['url']) ? $the_data['url'] : '';
}
...
<div><?php echo $your_object->getURL(); ?></div>