无需 foreach 的 PHP JSON 解码

问题描述 投票:0回答:1

如何在没有 foreach 循环的情况下从 i json 获取“avatarmedium”? 这是我当前的代码:

   $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;
php json decode
1个回答
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;
© www.soinside.com 2019 - 2024. All rights reserved.