【发布时间】:2021-11-22 05:52:29
【问题描述】:
我尝试从 API 返回,当我尝试返回 API 响应时,会产生此错误:
警告:尝试在第 3 行读取 C:\xampp\htdocs\samuraiacademy\wp-content\themes\twentyseventeen\template-parts\page\content-page.php 中数组的属性“id”
$vids = [];
$response = wp_remote_retrieve_body(wp_remote_get(
'https://developer.dacast.com/v2/vod',
array(
'timeout' => 10,
'headers' => array(
'X-Format' => 'default'
'X-Api-Key' => '1631861596B5ShPC5xLXu9yjQUqiYfy9KbRUUA6FWr',
)
)
));
$result = json_decode($response,true);
$vids[] = $result;
foreach($vids[0] as $vid){
print_r($vid[0]->id);
}
?>
如果我 var_dump($vids),
array(1) { [0]=> array(3) { ["data"]=> array(1) { [0]=> array(46) { ["abitrate"]=> int(1000 ) ["acodec"]=> string(3) "aac" ["ads"]=> NULL ["associated_packages"]=> string(0) "" ["autoplay"]=> bool(false) ["category_id "]=> int(0) ["container"]=> string(6) "mpeg-4" ["countries_id"]=> string(0) "" ["creation_date"]=> string(20) "2021 -09-27T08:36:48Z" ["custom_data"]=> NULL ["description"]=> string(7) "testing" ["disk_usage"]=> int(123849301) ["duration"]=> string (8) "00:00:01" ["enable_coupon"]=> bool(false) ["enable_payperview"]=> bool(false) ["enable_subscription"]=> bool(false) ["external_video_page"]=> string(7) "http://" ["filename"]=> string(10) "source.mp4" ["filesize"]=> string(8) "83061017" ["google_analytics"]=> int(0 ) ["group_id"]=> int(0) ["hds"]=> string(0) "" ["hls"]=> string(0) "" ["id"]=> string(36) " b2916e15-475e-3527-7b9c-3375bfaa2aa1"
【问题讨论】: