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

分享调用飞鲸电竞数据DOTA2的数据接口,在线接口文档,需注册

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 DotaTeam {
 
    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/DotaTeam.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 shortName;
        @JSONField
        private String alisa;
        @JSONField
        private String region;
        @JSONField
        private String introduction;
        @JSONField
        private String nation;
        @JSONField
        private int status;
        @JSONField
        private String logo;
        @JSONField
        private long buildTime;
        @JSONField
        private long overTime;
 
        @Override
        public String toString() {
            return "Team{" +
                    "teamId=" + teamId +
                    ", name='" + name + '\'' +
                    ", shortName='" + shortName + '\'' +
                    ", alisa='" + alisa + '\'' +
                    ", region='" + region + '\'' +
                    ", introduction='" + introduction + '\'' +
                    ", nation='" + nation + '\'' +
                    ", status=" + status +
                    ", logo='" + logo + '\'' +
                    ", buildTime=" + buildTime +
                    ", overTime=" + overTime +
                    '}';
        }
 
        public long getTeamId() {
            return teamId;
        }
 
        public void setTeamId(long teamId) {
            this.teamId = teamId;
        }
 
        public String getName() {
            return name;
        }
 
        public void setName(String name) {
            this.name = name;
        }
 
        public String getShortName() {
            return shortName;
        }
 
        public void setShortName(String shortName) {
            this.shortName = shortName;
        }
 
        public String getAlisa() {
            return alisa;
        }
 
        public void setAlisa(String alisa) {
            this.alisa = alisa;
        }
 
        public String getRegion() {
            return region;
        }
 
        public void setRegion(String region) {
            this.region = region;
        }
 
        public String getIntroduction() {
            return introduction;
        }
 
        public void setIntroduction(String introduction) {
            this.introduction = introduction;
        }
 
        public String getNation() {
            return nation;
        }
 
        public void setNation(String nation) {
            this.nation = nation;
        }
 
        public int getStatus() {
            return status;
        }
 
        public void setStatus(int status) {
            this.status = status;
        }
 
        public String getLogo() {
            return logo;
        }
 
        public void setLogo(String logo) {
            this.logo = logo;
        }
 
        public long getBuildTime() {
            return buildTime;
        }
 
        public void setBuildTime(long buildTime) {
            this.buildTime = buildTime;
        }
 
        public long getOverTime() {
            return overTime;
        }
 
        public void setOverTime(long overTime) {
            this.overTime = overTime;
        }
    }
}

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

200
成功
Team{teamId=-7, name='TBD', shortName='TBD', alisa='null', region='CN', introduction='', nation='CN', status=0, logo='http://qn.feijing88.com/feijing-home/egame/image/20190514/a2314fcd32744e178a611bee7d59249f.png', buildTime=0, overTime=0}
Team{teamId=1562, name='CDEC Gaming', shortName='CDEC', alisa='null', region='CN', introduction='CDEC-Gaming电子竞技俱乐部是中国新兴的DOTA2豪门,成立于2014年,承袭中国DotA精英联盟China DotA Elite Community的名号,希望能为中国DOTA2的发展带来更多新的景象和动力!CDEC曾以外卡赛战队的身份力夺第五届DOTA2国际邀请赛亚军而名扬中外,成为追梦选手书写中国刀塔电竞传奇的舞台!', nation='CN', status=1, logo='http://qn.feijing88.com/feijing-home/egame/image/20190514/1f2d91c3387d44ccb361c5df333e2f8a.jpg', buildTime=1388505600000, overTime=0}
Team{teamId=2109, name='VDuoBao', shortName='VDuoBao', alisa='null', region='CN', introduction='VDooBao是中国Dota 2队。在被VPGAME收购之前是DUOBAO团队。', nation='CN', status=1, logo='http://qn.feijing88.com/feijing-home/egame/image/20190514/b6d47f61bd23475e9b2e15d2b0fc123f.jpg', buildTime=1427817600000, overTime=0}
Team{teamId=2619, name='Invictus Gaming', shortName='iG', alisa='null', region='CN', introduction='Invictus Gaming(简称iG)是一家以电子竞技及周边业务为核心、旗下有多名国内顶级电子竞技选手的平台,目标之一是打造全球顶级电子竞技俱乐部。iG成立于2011年,目前设有五个分部,分别为LOL、DOTA2、星际2、炉石以及守望先锋。iG.DOTA分部作为iG最早的分部之一,多年来一直活跃在各大赛场上,为俱乐部获得多项荣誉,代表着国内顶尖水平,曾获得ti2国际预选赛冠军。DOTA分部拥有多名明星选手,深受粉丝喜爱。', nation='CN', status=1, logo='http://qn.feijing88.com/feijing-home/egame/image/20190813/fd264136c1e1434199085f06bd489e65.png', buildTime=1312214400000, overTime=0}
Team{teamId=2645, name='LGD.Forever Young', shortName='LFY', alisa='null', region='CN', introduction='LGD.DOTA2分部再次迎来双队时代!新成员——LGD.Forever young战队正式上线,如队名中Forever young所包含的意义一样,那些未竟的青春还将继续挥洒!', nation='CN', status=1, logo='http://qn.feijing88.com/feijing-home/egame/image/20190514/3f47c9edb1274d7a9d752250ab7e4229.jpg', buildTime=1474041600000, overTime=0}

相关推荐