乐趣区

电竞CSGO数据API接口-战队列表API调用示例代码

电竞 CSGO 数据 api 接口,可在线调用接口,需注册下

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: https://www.feijing88.com
 */
public class CsgoTeam {public static void main(String[] args) {
        try {String content = getContent();
            Respond rsp = JSON.parseObject(content, Respond.class);
            System.out.println(rsp.code);
            System.out.println(rsp.message);
            rsp.getData().forEach(System.out::println);
 
        } catch (Throwable t) {t.printStackTrace();
        }
    }
 
    /**
     * 获取 API 返回内容
     * <p>
     * Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
     */
    private static String getContent() {
        try {StringBuilder builder = new StringBuilder();
            List<String> lines = Files.readAllLines(Paths.get("./src/main/resources/CsgoTeam.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 List<Team> data;
 
        public int getCode() {return code;}
 
        public void setCode(int code) {this.code = code;}
 
        public String getMessage() {return message;}
 
        public void setMessage(String message) {this.message = message;}
 
        public List<Team> getData() {return data;}
 
        public void setData(List<Team> data) {this.data = data;}
    }
 
    public static class Team {
        @JSONField
        private long teamId;
        @JSONField
        private String name;
        @JSONField
        private String logo;
        @JSONField
        private String country;
        @JSONField
        private int worldRank;
        @JSONField
        private int weekInTop30;
        @JSONField
        private List<Integer> playerIds;
 
        @Override
        public String toString() {
            return "Team{" +
                    "teamId=" + teamId +
                    ", name='" + name + '\'' +
                    ", logo='" + logo + '\'' +
                    ", country='" + country + '\'' +
                    ", worldRank=" + worldRank +
                    ", weekInTop30=" + weekInTop30 +
                    ", playerIds=" + playerIds +
                    '}';
        }
 
        public void setTeamId(long teamId) {this.teamId = teamId;}
 
        public void setName(String name) {this.name = name;}
 
        public void setLogo(String logo) {this.logo = logo;}
 
        public void setCountry(String country) {this.country = country;}
 
        public void setWorldRank(int worldRank) {this.worldRank = worldRank;}
 
        public void setWeekInTop30(int weekInTop30) {this.weekInTop30 = weekInTop30;}
 
        public void setPlayerIds(List<Integer> playerIds) {this.playerIds = playerIds;}
    }
}

API 返回数据如下(部分):

200
成功
Team{teamId=620, name='fnatic', logo='http://qn.feijing88.com/feijing-home/egame/image/20190814/15497673e6544354b17fdeac064db7dc.jpg', country='Sweden', worldRank=0, weekInTop30=0, playerIds=[]}
Team{teamId=1001, name='Complexity', logo='http://qn.feijing88.com/feijing-home/egame/image/20190121/4befab749fe5476cbe117fc5e7acc301.jpg', country='United States', worldRank=27, weekInTop30=21, playerIds=[3460, 3438, 4391, 5714, 69269]}
Team{teamId=1046, name='NiP 2005', logo='http://qn.feijing88.com/feijing-home/egame/image/20190813/2b445859bcb34e4bb5aa573a1a5017ce.svg', country='Sweden', worldRank=0, weekInTop30=0, playerIds=[]}
Team{teamId=1053, name='[POD]Cast', logo='http://qn.feijing88.com/feijing-home/egame/image/20190813/6d775f19912a44aface895bbefa6b617.jpg', country='Other', worldRank=0, weekInTop30=0, playerIds=[]}
Team{teamId=1054, name='Episode #16', logo='http://qn.feijing88.com/feijing-home/egame/image/20190813/233113c7289e4147ac4c2c9179ca474f.svg', country='Europe', worldRank=0, weekInTop30=0, playerIds=[]}
Team{teamId=1060, name='ESEA Skills', logo='http://qn.feijing88.com/feijing-home/egame/image/20190813/7872f634ca2d480cbb16bc2949e73493.jpg', country='Other', worldRank=0, weekInTop30=0, playerIds=[]}
Team{teamId=1066, name='Competition', logo='http://qn.feijing88.com/feijing-home/egame/image/20190813/6c8842732cc64a0dbc39a2be9d09c05b.svg', country='Other', worldRank=0, weekInTop30=0, playerIds=[]}
Team{teamId=1067, name='ATE', logo='http://qn.feijing88.com/feijing-home/egame/image/20190129/ad4c83bfca0b489bb063ac4a38846d16.jpg', country='India', worldRank=0, weekInTop30=0, playerIds=[63147]}
退出移动版