3

この stdClass 構造を考えると...

[RecentAchievements] => stdClass Object
    (
        [1446] => stdClass Object
           (
               [3319] => stdClass Object
                   (
                       [ID] => 3319
                       [GameID] => 1446
                       [Title] => Hello World!
                       [Description] => Complete World 1-1
                       [Points] => 15
                       [BadgeName] => 03909
                       [IsAwarded] => 1
                       [DateAwarded] => 2013-10-20 19:35:46
                   )

「タイトル」など、3319 内のオブジェクトを確認する必要があるため、次のようになります。

$data->RecentAchievements->$gameid->ACHVIDHERE->Title;

$gameid を取得するには、他のオブジェクト (RecentlyPlayed) から次のように取得します。

[RecentlyPlayed] => Array
    (
        [0] => stdClass Object
            (
                [GameID] => 1446
                [ConsoleID] => 7
                [ConsoleName] => NES
                [Title] => Super Mario Bros
                [LastPlayed] => 2013-10-20 21:38:22
                [ImageIcon] => /Images/000385.png
                [ImageTitle] => /Images/000272.png
                [ImageIngame] => /Images/000387.png
                [ImageBoxArt] => /Images/000275.png
            )

    )

$gameid = $data3->RecentlyPlayed['0']->GameID;

API では、実績 ID を取得するために同じ RecentPlayed を使用できません。RecentAchievements から抽出する必要があります。出来ますか?

4

2 に答える 2

5

その特定のゲームの最初の成果の直後であれば、このハックを使用できます。

$firstAchievement = reset($data->RecentAchievements->$gameid);
$title = $firstAchievement->Title;

API はおそらく JSON 応答を返しているので、次の点も考慮する必要があります。

$data = json_decode($response, true);
                               ^^^^

2 番目のパラメーターtrueは、JavaScript オブジェクトを PHP 配列に変換します。これにより、ほとんどの場合、オブジェクトの処理が容易になります。

$firstAchievement = reset($data['RecentAchievements'][$gameid]);
$title = $firstAchievement['Title'];
于 2013-10-21T00:57:25.977 に答える
1

複雑なカーリー表記を使用して、オブジェクトの動的プロパティを参照できます

$data->RecentAchievements->{$gameid}->{$someotherid}->Title;

==と==を考えると、これはあなたHello World!に与えるはずです$gameid1446$someotherid3319

于 2013-10-21T00:23:50.833 に答える