类 stdClass 的对象无法使用 Halo API 转换为字符串


Object of class stdClass could not be converted to string with Halo API

所以我有以下代码:

    <?PHP
    $remote_url = 'https://www.haloapi.com/stats/h5/players/PLAYER/matches';
    // Create a stream
    $opts = array(
      'http'=>array(
        'method'=>"GET",
        'header' => "Ocp-Apim-Subscription-Key: MY SUBSCRIPTION KEY")                 
      );
    $context = stream_context_create($opts);
    // Open the file using the HTTP headers set above
    $file = file_get_contents($remote_url, false, $context);
    print(json_decode($file));
    ?>

它给了我以下错误:

可捕获的致命错误:类 stdClass 的对象无法转换为第 17 行 C:''xampp''htdocs''HaloAPItest''index.php 中的字符串

我该怎么办?

达伦在他的评论中说的。 print_r处理任何类的变量。 只打印字符串。

另一个有用的功能是var_dump。编写一个函数来像var_dump_pre一样做它并使其放 <pre> </pre> 标记。这在屏幕上很好地格式化了它。