Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问嵌套PHP对象的属性?_Php_Json_Stdclass - Fatal编程技术网

如何访问嵌套PHP对象的属性?

如何访问嵌套PHP对象的属性?,php,json,stdclass,Php,Json,Stdclass,我正在尝试做一个网络应用程序,人们可以看到他们在传奇联盟中的地位,但我甚至不知道如何做一些事情。我有一门课: stdClass Object ( [player] => stdClass Object ( [id] => xxxxxx [name] => yyyy [profileIconId] => 627 [summonerLevel] =>

我正在尝试做一个网络应用程序,人们可以看到他们在传奇联盟中的地位,但我甚至不知道如何做一些事情。我有一门课:

stdClass Object
(
    [player] => stdClass Object
        (
            [id] => xxxxxx
            [name] => yyyy
            [profileIconId] => 627
            [summonerLevel] => 30
            [revisionDate] => 1422798145000
        )
 )
我正在使用以下php代码:

我只想获取id、name和profileIconId并显示它。我不知道怎么做。
PD:我的英语不是很好,所以谢谢大家的编辑。

奇怪,我刚才还在看防暴API

我觉得你对这种类型的符号还很陌生,所以我会尽量快速但简洁地解释

正如杰里菲尔德所说,你所拥有的是物体。您可以使用->操作符访问它们的属性。例如,如果我假设对象$main是您要转储的对象,那么您可以简单地得到如下对象:

$main = json_decode($some_json_string);
//Now that we have the object set, we can deal with the properties.
echo $main->player->name; 
//This will output the player name. 
echo $main->player->id;
//Will output the player ID.
请注意,由于$main对象的player键也是一个对象,因此必须通过->操作符访问它的属性

但是,您也可以通过将第二个参数传递给json_decode来简单地使用关联数组,如下所示:

$main = json_decode($some_json_string,TRUE);
echo $main['player']['id'];
echo $main['player']['name'];

希望这会有所帮助。

这些只是对象,请使用->操作符访问这些值。例如$obj->player->id;亲爱的,谢谢你的回答,可能是重复的,但我做不到。我实际上使用的是官方的防暴API。你能给我加一个skype吗?只需要5分钟。用户:wesley.bdo。如果你不能,谢谢你。对不起,我不用Skype。
$main = json_decode($some_json_string,TRUE);
echo $main['player']['id'];
echo $main['player']['name'];