我一直在尝试使用JSON格式的Steam Web API。我一直在尝试打印API给出的数组输出。
<?php
$id = $_GET['id'];
$key = 'xxx';
$link = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $key . '&steamids=' . $id . '&format=json');
$profile_info = json_decode($link);
$json_response = json_encode($profile_info->response);
print($json_response['steamid']);
?>这把钥匙显然被Steam的发电机给我的钥匙替换了。但是我的这段代码只返回字符{,它应该返回76561197989628470,这是我的流。
以下是JSON格式的数组
{
"response": {
"players": [
{
"steamid": "76561197989628470",
"communityvisibilitystate": 3,
"profilestate": 1,
"personaname": "Archey",
"lastlogoff": 1334719151,
"commentpermission": 1,
"profileurl": "http://steamcommunity.com/id/Archey6/",
"avatar": "http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7.jpg",
"avatarmedium": "http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7_medium.jpg",
"avatarfull": "http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7_full.jpg",
"personastate": 1,
"primaryclanid": "103582791432066081",
"timecreated": 1177637717,
"loccountrycode": "CA",
"locstatecode": "SK"
}
]
}发布于 2012-04-19 11:11:32
为什么你先解码,然后再编码json?
<?php
$id = $_GET['id'];
$key = 'xxx';
$link = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $key . '&steamids=' . $id . '&format=json');
$myarray = json_decode($link, true);
print $myarray['response']['players'][0]['steamid'];
?>或者如果你真的需要重新编码:
<?php
$id = $_GET['id'];
$key = 'xxx';
$link = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $key . '&steamids=' . $id . '&format=json');
$profile_info = json_decode($link);
$json_response = json_encode($profile_info->response->players);
$decoded = json_decode($json_response, true);
print $json_response['steamid'];
?>https://stackoverflow.com/questions/10221101
复制相似问题