3

可能重复:
对象的属性名称中的特殊字符

我正在解析来自 MediaWiki 的 API 的 JSON 响应:请求的 URL

我运行它json_decode(),然后拉出一些碎片。我遇到的问题是内容的属性名称是*. 当我尝试访问内容时出现 PHP 错误(下面我的 vardumped json_decoded 示例末尾的 140,950 个字符串),如下所示:

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 对象:

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}}...

如何访问名为 * 的属性中包含的内容?

4

1 回答 1

9

一直如此。

...->{'*'}->...
于 2012-10-25T22:45:06.367 回答