属性名称为*时,如何解析PHP对象? [英] How do I parse a PHP object when the attribute name is *?
问题描述
可能重复:
对象属性名称中的特殊字符
Possible Duplicate:
Special characters in property name of object
I'm parsing a JSON response from MediaWiki's API: Requested URL
我通过json_decode()
运行它,然后拉一些它.我的问题是内容的属性名称是*
.当我尝试访问内容时(如下面的vardumped json_decoded示例末尾的140,950字符串),我收到PHP错误,如下所示:
I run it through json_decode()
and then pull some pieces of it. The problem I have is that the attribute name for the content is *
. I get a PHP error when I try to access the content ( the 140,950 character string at the end of my vardumped json_decoded example below ) like this:
foreach( $Response->query->pages as $page_id => $Page ) {
$this->id = $Page->pageid;
$this->title = $Page->title;
$this->content_with_markup = $Page->revisions[0]->*;
}
PHP错误:PHP Parse error: syntax error, unexpected '*'
pageid
和title
正常工作.
这是给我一些问题的JSON_Decoded对象:
Here is the piece of JSON_Decoded object that is giving me problems:
object(stdClass)#5 (1) {
["11968"]=>
object(stdClass)#6 (4) {
["pageid"]=>
int(11968)
["ns"]=>
int(0)
["title"]=>
string(17) "George Washington"
["revisions"]=>
array(1) {
[0]=>
object(stdClass)#7 (2) {
["contentformat"]=>
string(11) "text/x-wiki"
["*"]=>
string(140950) "{{About|the first President of the United States|other uses}}...
如何访问名为*的属性中包含的内容?
推荐答案
一如既往.
...->{'*'}->...
这篇关于属性名称为*时,如何解析PHP对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!