欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CSGO电竞API数据接口 - 【选手信息】API调用示例代码

程序员文章站 2022-06-01 14:50:05
...

CS:GO电竞API专用数据接口 分享使用代码
分享使用 椰子电竞 http://www.yezidianjing.com/接口调用的示例代码
接口分为:
CS:GO【战队列表】
CS:GO【选手信息】
CS:GO【历史对战】

示例演示:CSGO的【选手信息】接口
具体如下
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**

  • @API: 选手基本信息

  • @Website: http://www.yezidianjing.com/
    */
    public class CsgoPlayer {

    public static void main(String[] args) {
    try {
    String content = getContent();
    Respond rsp = JSON.parseObject(content, Respond.class);
    System.out.println(rsp);

     } catch (Throwable t) {
         t.printStackTrace();
     }
    

    }

    /**

    • 获取API返回内容
    • Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
      */
      private static String getContent() {
      try {
      StringBuilder builder = new StringBuilder();
      List lines = Files.readAllLines(Paths.get("./src/main/resources/CsgoPlayer.json"), StandardCharsets.UTF_8);
      lines.forEach(builder::append);
      return builder.toString();
      } catch (Throwable t) {
      t.printStackTrace();
      return “”;
      }
      }

    public static class Respond {
    @JSONField
    private int code;
    @JSONField
    private String message;
    @JSONField
    private Player data;

     @Override
     public String toString() {
         return "Respond{" +
                 "code=" + code +
                 ", message='" + message + '\'' +
                 ", data=" + data +
                 '}';
     }
    
     public void setCode(int code) {
         this.code = code;
     }
    
     public void setMessage(String message) {
         this.message = message;
     }
    
     public void setData(Player data) {
         this.data = data;
     }
    

    }

    public static class Player {

     @JSONField
     private int playerId;
     @JSONField
     private int teamId;
     @JSONField
     private String avatar;
     @JSONField
     private String nickName;
     @JSONField
     private String realName;
     @JSONField
     private int age;
     @JSONField
     private String country;
    
     @Override
     public String toString() {
         return "Player{" +
                 "playerId=" + playerId +
                 ", teamId=" + teamId +
                 ", avatar='" + avatar + '\'' +
                 ", nickName='" + nickName + '\'' +
                 ", realName='" + realName + '\'' +
                 ", age=" + age +
                 ", country='" + country + '\'' +
                 '}';
     }
    
     public void setPlayerId(int playerId) {
         this.playerId = playerId;
     }
    
     public void setTeamId(int teamId) {
         this.teamId = teamId;
     }
    
     public void setAvatar(String avatar) {
         this.avatar = avatar;
     }
    
     public void setNickName(String nickName) {
         this.nickName = nickName;
     }
    
     public void setRealName(String realName) {
         this.realName = realName;
     }
    
     public void setAge(int age) {
         this.age = age;
     }
    
     public void setCountry(String country) {
         this.country = country;
     }
    

    }

}