gpt4 book ai didi

php - 从 stdClass 对象数组中获取数据

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:05:25 26 4
gpt4 key购买 nike

我正在尝试从 Vimeo Api 中检索该字段的值,我已经尝试了此处提到的所有可能的解决方案。谁能告诉我如何分别从缩略图和 url 对象中检索缩略图和 url?

array(1) {
[0]=>
stdClass Object (
[allow_adds] => 1
[embed_privacy] => anywhere
[id] => 123456789
[is_hd] => 0
[is_transcoding] => 0
[license] => 0
[privacy] => anybody
[title] => Soap Opera
[description] =>
[upload_date] => 2014-02-20 03:03:50
[modified_date] => 2014-02-20 19:06:05
[number_of_plays] => 1
[number_of_likes] => 0
[number_of_comments] => 0
[width] => 600
[height] => 480
[duration] => 32
[owner] => stdClass Object (
[display_name] => blah
[id] => 12345678
[is_plus] => 0
[is_pro] => 1
[is_staff] => 0
[profileurl] => http://vimeo.com/st
[realname] => ST
[username] => ST
[videosurl] => http://vimeo.com/st/videos
[portraits] => stdClass Object (
[portrait] => Array (
[0] => stdClass Object (
[height] => 30
[width] => 30
[_content] => http://b.vimeocdn.com/x.jpg
)

[1] => stdClass Object (
[height] => 75
[width] => 75
[_content] => http://b.vimeocdn.com/x.jpg
)

[2] => stdClass Object (
[height] => 100
[width] => 100
[_content] => http://b.vimeocdn.com/x.jpg
)

[3] => stdClass Object (
[height] => 300
[width] => 300
[_content] => http://b.vimeocdn.com/x.jpg
)

)

)

)

[urls] => stdClass Object (
[url] => Array (
[0] => stdClass Object (
[type] => video
[_content] => http://vimeo.com/0000
)
)
)

[thumbnails] => stdClass Object (
[thumbnail] => Array (
[0] => stdClass Object (
[height] => 75
[width] => 100
[_content] => http://b.vimeocdn.com/x.jpg
)
)
)
)

我有一个数组 $vids ,它包含各种视频的元信息以及循环内的另一个调用,该循环获取第二个数组 $vidInfo 包含上面显示的数组对于每个条目。我可以像正常访问对象一样检索标题等。但我无法再遍历上面的响应。

<?php 
$vids = $videos->videos->video;
foreach ($vids as $vid){
$id = $vid->id;
$vidInfo = $vimeo->call('vimeo.videos.getInfo', array('video_id' => $id));
$vidUrl = $vidInfo->video;
echo $vid->title;
echo '<br />';
print_r($vidUrl->urls->url[0]->{'_content'});
//echo '<pre>' . print_r($vidUrl) . '</pre>';
}
?>

非常感谢

最佳答案

考虑到你有:

    [urls] => stdClass Object
(
[url] => Array
(
[0] => stdClass Object
(
[type] => video
[_content] => http://vimeo.com/0000
)

)

)

访问对象是通过对象访问运算符 (->) 完成的,而访问数组是通过方括号 ([x]) 完成的。所以在这种情况下,您最终会得到 urls->url[0]->_content。由于 urls 是一个对象,而 url 是一个数组,其第一个 ([0]) 索引包含另一个对象。

简而言之,回答您的完整原始问题:$object->urls->url[0]->_content 是网址和$object->thumbnails->thumbnail[0]->_content为缩略图

关于php - 从 stdClass 对象数组中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22660539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com