我正在尝试使用Steam的Web API回显某个CS:GO播放器的游戏统计数据。
我抓住了这个文件:
$gamestatlink = file_get_contents('http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=<<MY API KEY>>&steamid=<<PLAYERS STEAM ID>>&format=json');
$statarray = json_decode($gamestatlink, true);
并尝试用
回显该行echo $statarray['playerstats']['stats'][0]['total_kills'][0];
但是,echo返回空。
文件返回
{ "playerstats": { "steamID": ">", "gameName": "ValveTestApp260", "stats": [ { "name": "total_kills", "value": 508 }, { "name": "total_deaths", "value": 1100 }, { "name": "total_time_played", "value": 106761 }, { "name": "total_planted_bombs", "value": 8 }, { "name": "total_defused_bombs", "value": 10 }, { "name": "total_wins", "value": 558 }, { "name": "total_damage_done", "value": 74944 }, { "name": "total_money_earned", "value": 3262500 }, { "name": "total_kills_knife", "value": 3 }, { "name": "total_kills_glock", "value": 13 }, { "name": "total_kills_deagle", "value": 2 }, { "name": "total_kills_elite", "value": 1 }, { "name": "total_kills_fiveseven", "value": 14 }, { "name": "total_kills_xm1014", "value": 7 }, { "name": "total_kills_ump45", "value": 1 }, { "name": "total_kills_p90", "value": 2 }, { "name": "total_kills_awp", "value": 4 }, { "name": "total_kills_ak47", "value": 11 }, { "name": "total_kills_aug", "value": 250 }, { "name": "total_kills_famas", "value": 15 }, { "name": "total_kills_m249", "value": 1 }, { "name": "total_kills_headshot", "value": 199 }, { "name": "total_kills_enemy_weapon", "value": 14 }, { "name": "total_wins_pistolround", "value": 4 }, { "name": "total_wins_map_cs_assault", "value": 3 }, { "name": "total_wins_map_de_cbble", "value": 16 }, { "name": "total_wins_map_de_dust2", "value": 225 }, { "name": "total_wins_map_de_dust", "value": 16 }, { "name": "total_wins_map_de_inferno", "value": 123 }, { "name": "total_wins_map_de_train", "value": 21 }, { "name": "total_weapons_donated", "value": 61 }, { "name": "total_broken_windows", "value": 2 }, { "name": "total_kills_enemy_blinded", "value": 3 }, { "name": "total_kills_knife_fight", "value": 3 }, { "name": "total_kills_against_zoomed_sniper", "value": 58 }, { "name": "total_shots_hit", "value": 2534 }, { "name": "total_shots_fired", "value": 17261 }, { "name": "total_rounds_played", "value": 1264 }, { "name": "total_shots_deagle", "value": 61 }, { "name": "total_shots_glock", "value": 707 }, { "name": "total_shots_elite", "value": 74 }, { "name": "total_shots_fiveseven", "value": 204 }, { "name": "total_shots_awp", "value": 38 }, { "name": "total_shots_ak47", "value": 427 }, { "name": "total_shots_aug", "value": 6669 }, { "name": "total_shots_famas", "value": 868 }, { "name": "total_shots_p90", "value": 156 }, { "name": "total_shots_ump45", "value": 41 }, { "name": "total_shots_xm1014", "value": 624 }, { "name": "total_shots_m249", "value": 42 }, { "name": "total_hits_deagle", "value": 8 }, { "name": "total_hits_glock", "value": 125 }, { "name": "total_hits_elite", "value": 15 }, { "name": "total_hits_fiveseven", "value": 37 }, { "name": "total_hits_awp", "value": 6 }, { "name": "total_hits_ak47", "value": 35 }, { "name": "total_hits_aug", "value": 1115 }, { "name": "total_hits_famas", "value": 77 }, { "name": "total_hits_p90", "value": 14 }, { "name": "total_hits_ump45", "value": 2 }, { "name": "total_hits_xm1014", "value": 90 }, { "name": "total_hits_m249", "value": 1 }, { "name": "total_rounds_map_cs_assault", "value": 9 }, { "name": "total_rounds_map_cs_office", "value": 1 }, { "name": "total_rounds_map_de_cbble", "value": 44 }, { "name": "total_rounds_map_de_dust2", "value": 523 }, { "name": "total_rounds_map_de_dust", "value": 20 }, { "name": "total_rounds_map_de_inferno", "value": 256 }, { "name": "total_rounds_map_de_train", "value": 61 }, { "name": "last_match_t_wins", "value": 8 }, { "name": "last_match_ct_wins", "value": 2 }, { "name": "last_match_wins", "value": 2 }, { "name": "last_match_max_players", "value": 20 }, { "name": "last_match_kills", "value": 5 }, { "name": "last_match_deaths", "value": 12 }, { "name": "last_match_mvps", "value": 0 }, { "name": "last_match_favweapon_id", "value": 8 }, { "name": "last_match_favweapon_shots", "value": 66 }, { "name": "last_match_favweapon_hits", "value": 12 }, { "name": "last_match_favweapon_kills", "value": 3 }, { "name": "last_match_damage", "value": 637 }, { "name": "last_match_money_spent", "value": 29700 }, { "name": "total_mvps", "value": 30 }, { "name": "total_matches_won", "value": 46 }, { "name": "total_matches_played", "value": 113 }, { "name": "total_contribution_score", "value": 1083 }, { "name": "last_match_contribution_score", "value": 10 }, { "name": "last_match_rounds", "value": 10 }, { "name": "total_kills_hkp2000", "value": 58 }, { "name": "total_shots_hkp2000", "value": 1673 }, { "name": "total_hits_hkp2000", "value": 373 }, { "name": "total_shots_p250", "value": 16 }, { "name": "total_kills_sg556", "value": 64 }, { "name": "total_shots_sg556", "value": 1705 }, { "name": "total_hits_sg556", "value": 239 }, { "name": "total_hits_scar20", "value": 3 }, { "name": "total_kills_scar20", "value": 2 }, { "name": "total_shots_scar20", "value": 26 }, { "name": "total_shots_ssg08", "value": 49 }, { "name": "total_hits_ssg08", "value": 8 }, { "name": "total_kills_ssg08", "value": 3 }, { "name": "total_shots_mp7", "value": 172 }, { "name": "total_hits_mp7", "value": 34 }, { "name": "total_kills_mp7", "value": 9 }, { "name": "total_hits_nova", "value": 262 }, { "name": "total_kills_nova", "value": 28 }, { "name": "total_shots_nova", "value": 2037 }, { "name": "total_hits_negev", "value": 2 }, { "name": "total_shots_negev", "value": 91 }, { "name": "total_shots_sawedoff", "value": 56 }, { "name": "total_shots_bizon", "value": 88 }, { "name": "total_hits_bizon", "value": 4 }, { "name": "total_kills_tec9", "value": 3 }, { "name": "total_shots_tec9", "value": 117 }, { "name": "total_hits_tec9", "value": 16 }, { "name": "total_shots_mag7", "value": 144 }, { "name": "total_hits_mag7", "value": 18 }, { "name": "total_kills_m4a1", "value": 10 }, { "name": "total_kills_galilar", "value": 7 }, { "name": "total_shots_m4a1", "value": 640 }, { "name": "total_shots_galilar", "value": 535 }, { "name": "total_shots_taser", "value": 1 }, { "name": "total_hits_m4a1", "value": 41 }, { "name": "total_hits_galilar", "value": 39 }, { "name": "total_matches_won_train", "value": 1 }, { "name": "GI.lesson.csgo_instr_explain_buymenu", "value": 16 }, { "name": "GI.lesson.csgo_instr_explain_buyarmor", "value": 16 }, { "name": "GI.lesson.csgo_instr_explain_plant_bomb", "value": 16 }, { "name": "GI.lesson.csgo_instr_explain_bomb_carrier", "value": 1 }, { "name": "GI.lesson.bomb_sites_A", "value": 1 }, { "name": "GI.lesson.defuse_planted_bomb", "value": 1 }, { "name": "GI.lesson.csgo_instr_explain_follow_bomber", "value": 1 }, { "name": "GI.lesson.csgo_instr_explain_pickup_bomb", "value": 1 }, { "name": "GI.lesson.csgo_instr_explain_prevent_bomb_pickup", "value": 1 }, { "name": "GI.lesson.Csgo_cycle_weapons_kb", "value": 16 }, { "name": "GI.lesson.csgo_instr_explain_zoom", "value": 16 }, { "name": "GI.lesson.csgo_instr_explain_reload", "value": 17 }, { "name": "GI.lesson.tr_explain_plant_bomb", "value": 16 }, { "name": "GI.lesson.version_number", "value": 16 }, { "name": "GI.lesson.find_planted_bomb", "value": 1 }, { "name": "GI.lesson.csgo_instr_rescue_zone", "value": 1 }, { "name": "GI.lesson.csgo_instr_explain_inspect", "value": 32 } ] , "achievements": [ { "name": "WIN_BOMB_PLANT", "achieved": 1 }, { "name": "KILL_ENEMY_LOW", "achieved": 1 }, { "name": "KILL_ENEMY_MED", "achieved": 1 }, { "name": "BOMB_DEFUSE_CLOSE_CALL", "achieved": 1 }, { "name": "WIN_BOMB_DEFUSE", "achieved": 1 }, { "name": "WIN_ROUNDS_LOW", "achieved": 1 }, { "name": "WIN_ROUNDS_MED", "achieved": 1 }, { "name": "GIVE_DAMAGE_LOW", "achieved": 1 }, { "name": "GIVE_DAMAGE_MED", "achieved": 1 }, { "name": "EARN_MONEY_LOW", "achieved": 1 }, { "name": "EARN_MONEY_MED", "achieved": 1 }, { "name": "KILL_ENEMY_AUG", "achieved": 1 }, { "name": "KILL_ENEMY_TEAM", "achieved": 1 }, { "name": "LAST_PLAYER_ALIVE", "achieved": 1 }, { "name": "KILL_ENEMY_LAST_BULLET", "achieved": 1 }, { "name": "DAMAGE_NO_KILL", "achieved": 1 }, { "name": "KILL_LOW_DAMAGE", "achieved": 1 }, { "name": "KILL_ENEMY_RELOADING", "achieved": 1 }, { "name": "KILL_ENEMIES_WHILE_BLIND", "achieved": 1 }, { "name": "WIN_KNIFE_FIGHTS_LOW", "achieved": 1 }, { "name": "HIP_SHOT", "achieved": 1 }, { "name": "KILL_WHEN_AT_LOW_HEALTH", "achieved": 1 }, { "name": "FAST_ROUND_WIN", "achieved": 1 }, { "name": "LOSSLESS_EXTERMINATION", "achieved": 1 }, { "name": "UNSTOPPABLE_FORCE", "achieved": 1 }, { "name": "IMMOVABLE_OBJECT", "achieved": 1 }, { "name": "WIN_MAP_DE_DUST2", "achieved": 1 }, { "name": "WIN_MAP_DE_INFERNO", "achieved": 1 }, { "name": "KILL_ENEMY_IN_AIR", "achieved": 1 }, { "name": "KILL_BOMB_PICKUP", "achieved": 1 }, { "name": "AVENGE_FRIEND", "achieved": 1 } ] } }
我使用类似的代码来读取播放器摘要文件,其结构略有不同,但代码可以正常工作。
我正试图抓住value
的{{1}}。
我做错了什么?
提前致谢。
编辑:
我不觉得How can I access an array/object?的答案在这里对我有帮助,因为返回数组的结构不同,并且使用了不同的api。