【问题标题】:Getting json data from php ( or array?) [duplicate]从php(或数组?)获取json数据[重复]
【发布时间】:2017-08-17 20:17:50
【问题描述】:

我需要从这里https://use.gameapis.net/mc/query/info/play.mineverge.net获取JSON数据

我需要“在线”:126 显示在我的网页中。

"players": {
    "online": 126,
    "max": 500

这是我当前获取 JSON 的代码(不工作)。难道我做错了什么?它显示所有内容,而不仅仅是“在线”:

             $playeronline = file_get_contents ('https://use.gameapis.net/mc/query/info/' . $server); 
            echo $playeronline->players[1]; 
            echo $playeronline['online']; 

【问题讨论】:

    标签: php json server


    【解决方案1】:

    这对我有用,我对其进行了测试:

    $str = file_get_contents ('https://use.gameapis.net/mc/query/info/play.mineverge.net');
    
    $playersonline = json_decode( $str );
    
    echo $playersonline->players->online;
    

    【讨论】:

      【解决方案2】:

      试试这个,

      $playeronline = file_get_contents ('https://use.gameapis.net/mc/query/info/' . $server); 
      $data=json_decode($playeronline,true);
      
      echo $data['players']['online']; 
      

      【讨论】:

        【解决方案3】:

        here 所述,您需要使用json_decode 函数,如下所示:

        $playeronline = file_get_contents('https://use.gameapis.net/mc/query/info/' . $server); 
        
        $obj = json_decode($playeronline );
        echo $playersonline->players->online;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-08-30
          • 2020-04-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-11-14
          相关资源
          最近更新 更多