访问以美元符号作为节点名称的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'];