我正在尝试从 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/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我的代码目前看起来像这样numbers=[1,2,3,4,5]defpop_threepop=[]3.times{pop有没有办法在一行中完成pop_three方法中的内容?我基本上想做类似numbers.slice(0,3)的事情,但要删除切片中的数组项。嗯...嗯,我想我刚刚意识到我可以试试slice! 最佳答案 是numbers.pop(3)或者numbers.shift(3)如果你想要另一边。 关于ruby-多次弹出/移动ruby数组,我们在StackOverflow上找到一
我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]
我正在使用puppet为ruby程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信
这个问题在这里已经有了答案:Checktoseeifanarrayisalreadysorted?(8个答案)关闭9年前。我只是想知道是否有办法检查数组是否在增加?这是我的解决方案,但我正在寻找更漂亮的方法:n=-1@arr.flatten.each{|e|returnfalseife