电竞英雄联盟数据API接口 - 【近期赛事列表】API调用示例代码

分享使用 飞鲸体育数据 www.feijing88.com 接口调用的示例代码,今天接的是英雄联盟的【近期赛事列表】接口.

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 LolMatch {

    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.getMatchList().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/LolMatch.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(name = "data")
        private List<Match> matchList;

        public void setCode(int code) {
            this.code = code;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public void setMatchList(List<Match> matchList) {
            this.matchList = matchList;
        }

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }

        public List<Match> getMatchList() {
            return matchList;
        }
    }

    public static class Match {
        @JSONField
        private long matchId;
        @JSONField
        private long leagueId;
        @JSONField
        private int status;
        @JSONField
        private long startTime;
        @JSONField
        private String address;
        @JSONField
        private String roundName;
        @JSONField
        private String roundSonName;
        @JSONField
        private int bo;
        @JSONField
        private List<Integer> battleIds;
        @JSONField
        private int teamAScore;
        @JSONField
        private int teamAId;
        @JSONField
        private int teamBScore;
        @JSONField
        private int teamBid;

        @Override
        public String toString() {
            return "Match{" +
                    "matchId=" + matchId +
                    ", leagueId=" + leagueId +
                    ", status=" + status +
                    ", startTime=" + startTime +
                    ", address='" + address + '\'' +
                    ", roundName='" + roundName + '\'' +
                    ", roundSonName='" + roundSonName + '\'' +
                    ", bo=" + bo +
                    ", battleIds=" + battleIds +
                    ", teamAScore=" + teamAScore +
                    ", teamAId=" + teamAId +
                    ", teamBScore=" + teamBScore +
                    ", teamBid=" + teamBid +
                    '}';
        }

        public void setMatchId(long matchId) {
            this.matchId = matchId;
        }

        public void setLeagueId(long leagueId) {
            this.leagueId = leagueId;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public void setStartTime(long startTime) {
            this.startTime = startTime;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public void setRoundName(String roundName) {
            this.roundName = roundName;
        }

        public void setRoundSonName(String roundSonName) {
            this.roundSonName = roundSonName;
        }

        public void setBo(int bo) {
            this.bo = bo;
        }

        public void setBattleIds(List<Integer> battleIds) {
            this.battleIds = battleIds;
        }

        public void setTeamAScore(int teamAScore) {
            this.teamAScore = teamAScore;
        }

        public void setTeamAId(int teamAId) {
            this.teamAId = teamAId;
        }

        public void setTeamBScore(int teamBScore) {
            this.teamBScore = teamBScore;
        }

        public void setTeamBid(int teamBid) {
            this.teamBid = teamBid;
        }
    }
}

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

200
成功
Match{matchId=3186, leagueId=670, status=0, startTime=1565082000000, address='上海', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=789, teamBScore=0, teamBid=66}
Match{matchId=3101, leagueId=670, status=0, startTime=1565089200000, address='北京RNG', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=1, teamBScore=0, teamBid=722}
Match{matchId=3102, leagueId=670, status=0, startTime=1565168400000, address='重庆', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=79, teamBScore=0, teamBid=73}
Match{matchId=3103, leagueId=670, status=0, startTime=1565175600000, address='杭州', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=74, teamBScore=0, teamBid=63}
Match{matchId=3255, leagueId=678, status=0, startTime=1565251200000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=49, teamBScore=0, teamBid=40}
Match{matchId=3300, leagueId=678, status=0, startTime=1565262000000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=703, teamBScore=0, teamBid=44}
Match{matchId=3306, leagueId=678, status=0, startTime=1565337600000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=46, teamBScore=0, teamBid=704}
Match{matchId=3105, leagueId=670, status=0, startTime=1565341200000, address='上海', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=79, teamBScore=0, teamBid=6}
Match{matchId=3104, leagueId=670, status=0, startTime=1565348400000, address='西安', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=70, teamBScore=0, teamBid=789}
Match{matchId=3307, leagueId=678, status=0, startTime=1565348400000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=4, teamBScore=0, teamBid=708}
上一篇:将Long类型转换成String类型


下一篇:[JAVA]-Java中使用JSON(整理)