没有foreach的PHP JSON解码

时间:2017-10-28 22:09:51

标签: php json decode

我怎样才能获得" avatarmedium"来自i json没有foreach Loop? 这是我现在的代码:

   $json = '{
    "response": {
        "players": [
            {
                "steamid": "76561198019025166",
                "avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d3/d3ca76e0f1e8d071e826bc3baeebd0e7215e50e2_medium.jpg"

            }
        ]

    }
}';

$result = json_decode ($json);
echo $json->response[0]->players->profileurl;

谢谢 最诚挚的问候

1 个答案:

答案 0 :(得分:1)

<?php
       $json = '{
    "response": {
        "players": [
            {
                "steamid": "76561198019025166",
                "avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d3/d3ca76e0f1e8d071e826bc3baeebd0e7215e50e2_medium.jpg"

            }
        ]

    } }';

$result = json_decode ($json); 
echo $result->response->players[0]->avatarmedium;