首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取JSON数据,wikimedia

获取JSON数据,wikimedia
EN

Stack Overflow用户
提问于 2016-04-10 20:18:36
回答 1查看 70关注 0票数 0

问题

我有这个JSON内容,这是我从wikimedia API获得的JSON格式。我想在* this下提取数据。虽然我不知道在调用页面id之前,所以我不能使用中间的页面。此外,我也不知道如何传递收敛性(* )。我使用以下代码来获取数据,但得到了一个错误。

我非常感谢你的帮助和指导。

代码语言:javascript
复制
$api_data->query->pages->revisions[0]->['*'];

JSON

代码语言:javascript
复制
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.
                                        )

                                )

                        )

                )

        )

)
EN

回答 1

Stack Overflow用户

发布于 2016-04-10 20:56:52

您可以使用Chay22建议的方括号中的属性名称:

代码语言:javascript
复制
$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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36535062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档