尝试读取属性"id"返回 http 响应时出错



我尝试从API返回,当我尝试返回API响应时,这个错误产生:

警告:试图读取属性"id"在C:xampphtdocssamuraiacademywp-contentthemes 20117 template-partspagecontent-page.php on line 3

$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]=>数组(3){["data"]=>数组(1){[0]=>Array (46) {[" bitrate"]=>int(1000)("acodec" =比;字符串(3)"aac"("ads" =比;零("associated_packages" =比;字符串(0)";"("autoplay" =比;bool (false)("category_id" =比;int(0)("container" =比;字符串(6)"mpeg-4"("countries_id" =比;字符串(0)";"("creation_date" =比;字符串(20)"2021 - 09 - 27 t08:36:48z"("custom_data" =比;零("description" =比;字符串(7)"testing"("disk_usage" =比;int(123849301)("duration" =比;字符串(8)"00:00:01"("enable_coupon" =比;bool (false)("enable_payperview" =比;bool (false)("enable_subscription" =比;bool (false)("external_video_page" =比;字符串(7)"http://"("filename" =比;字符串(10)"source.mp4"("filesize" =比;字符串(8)"83061017";("google_analytics" =比;int(0)("group_id" =比;int(0)("hds" =比;字符串(0)";"("hls" =比;字符串(0)";"("id" =比;字符串(36)"b2916e15 - 475 - e - 3527 - 7 - b9c - 3375 bfaa2aa1"

不需要将$result存储在数组变量中你会得到这样的ID

$results = json_decode($response,true);

foreach($results as $result){
print_r($result['id']);
}