【问题标题】:PHP JSON Steam API request and printPHP JSON Steam API 请求和打印
【发布时间】:2015-03-31 12:26:27
【问题描述】:

我的代码有什么问题?我想打印像 total_time_played 和更多细节。

$url = 'http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=7BBE9B2D821CEBBC0F4944912BE26DC5&steamid=76561197980138287';
$urljson = file_get_contents('$url');


$data = json_decode($urljson)->playerstats;

$new_array = array();
foreach ($data->stats as $item) {
    $new_array[$item->name] = $item->value;
}
echo $new_array['total_time_played'];

【问题讨论】:

  • 我猜你不是说你只打印total_time_played 而你忘了打印任何其他细节,所以......你到底有什么问题?
  • 我的 total_time_played 是 600254,我很想在我的网站上打印。
  • 请说明您遇到问题的地方。您当前的脚本做什么与您的预期不同?您做了哪些调试来确定脚本的行为与预期不同的地方?

标签: arrays json steam


【解决方案1】:

在这里,您将尝试从文字 '$url' 字符串中获取内容,而不是您的 $url 变量的字符串值。

这个:

$urljson = file_get_contents('$url');

需要改成这样:

$urljson = file_get_contents($url);

注意单引号(防止变量插值)已被删除。

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 2013-01-10
    • 1970-01-01
    • 2021-08-02
    相关资源
    最近更新 更多