Access a PHP-object with dollar-sign as node name(使用美元符号作为节点名称访问 PHP 对象)
问题描述
我正在使用每个 PHP 的 YouTube 数据 API,并以 json 格式向特定用户请求视频供稿.json_decode 后的结果如下(简化示例):
I'm working with the YouTube Data API per PHP and requesting a video feed from a specific user in json-format. The result after json_decode is the following (shortened example):
stdClass Object
(
[version] => 1.0
[encoding] => UTF-8
[feed] => stdClass Object
(
[xmlns] => http://www.w3.org/2005/Atom
[xmlns$media] => http://search.yahoo.com/mrss/
[xmlns$openSearch] => http://a9.com/-/spec/opensearchrss/1.0/
[xmlns$gd] => http://schemas.google.com/g/2005
[xmlns$yt] => http://gdata.youtube.com/schemas/2007
)
)
我的问题是:如何使用 PHP 访问例如节点xmlns$media"?在美元符号内它不起作用还是有一种我还没有得到的方法?
My question is: how can I access for example the node "xmlns$media" with PHP? Within the dollar-sign it won't work or is there a way which I didn't get yet?
推荐答案
这将起作用:
echo $object->feed->{'xmlns$media'};
或者,您可以告诉 json_decode
返回一个数组:
Alternatively, you can tell json_decode
to return an array:
$array = json_decode($json, true);
echo $array['feed']['xmlns$media'];
这篇关于使用美元符号作为节点名称访问 PHP 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用美元符号作为节点名称访问 PHP 对象


基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01