I'm trying to display the values of a JSON with PHP most unsuccessfully. Used Code:
JSON
{ "friendslist": { "friends": [ { "steamid": "76561197960265731", "relationship": "friend", "friend_since": 0 }, { "steamid": "76561197960265738", "relationship": "friend", "friend_since": 0 }, { "steamid": "76561197960265740", "relationship": "friend", "friend_since": 0 }, { "steamid": "76561197960265747", "relationship": "friend", "friend_since": 0 } ] } }PHP
$steamid_player = "76561198112612121"; $apikey = "APIKEY";$amg = file_get_contents("http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=$apikey&steamid=$steamid_player&relationship=friend"); $decode = json_decode($amg, TRUE); foreach ($decode["friendslist"]["friends"][0] as $valor){ $steamid = $valor["relationship"]->steamid; echo $steamid; }
Error returned
Warning: Illegal string offset 'relationship' in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\leo\test.php on line 10 Notice: Trying to get property of non-object in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\leo\test.php on line 10 Warning: Illegal string offset 'relationship' in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\leo\test.php on line 10 Notice: Trying to get property of non-object in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\leo\test.php on line 10 Notice: Trying to get property of non-object in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\leo\test.php on line 10
But an error is always returned, so no value is displayed. Where am I going wrong?