2017-10-28 110 views
1

我怎樣才能從i json的「avatarmedium」沒有foreach循環? 那是我當前的代碼:PHP JSON解碼沒有foreach

$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
<?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;