问题
我有这个JSON内容,这是我从wikimedia API获得的JSON格式。我想在* this下提取数据。虽然我不知道在调用页面id之前,所以我不能使用中间的页面。此外,我也不知道如何传递收敛性(* )。我使用以下代码来获取数据,但得到了一个错误。
我非常感谢你的帮助和指导。
码
$api_data->query->pages->revisions[0]->['*'];JSON
stdClass Object
(
[batchcomplete] =>
[query] => stdClass Object
(
[pages] => stdClass Object
(
[27000] => stdClass Object
(
[pageid] => 27000
[ns] => 0
[title] => Patna
[revisions] => Array
(
[0] => stdClass Object
(
[contentformat] => text/x-wiki
[contentmodel] => wikitext
[*] => ==Understand==
The ancient name of Patna was 'Pataliputra' and it was the capital of the Maurya and Gupta empires. Located at the site where Patna is today, the ancient city of Patliputra, with a glorious period of history spanning a thousand years (500BC-400AD), saw the rise and fall of India's first major kingdoms.
Lying along the banks of the Ganges River, Patna is surrounded by important religious centers for the Buddhists, Sikhs and Jains. This city has been home to two great religions, Buddhism and Jainism, and myriad dynasties from ancient to modern times.
)
)
)
)
)
)发布于 2016-04-10 20:56:52
您可以使用Chay22建议的方括号中的属性名称:
$data->first = 'hello';
$data->{'*'} = 'world';
var_dump($data);
// Like this
echo $data->{'*'};
echo PHP_EOL;
// or like this
$varname = '*';
echo $data->{$varname};
echo PHP_EOL;https://stackoverflow.com/questions/36535062
复制相似问题