王者荣耀 赛事数据api接口示例

分享使用王者荣耀的 赛事数据 接口示例,详情可查看接口介绍,可注册下

package com.huaying.demo.esport;
 
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 KogMatch {
 
    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/KogMatch.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 String address;
        @JSONField
        private int status;
        @JSONField
        private long startTime;
        @JSONField
        private long roundId;
        @JSONField
        private String roundName;
        @JSONField
        private String roundSonName;
        @JSONField
        private int bo;
        @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 +
                    ", address='" + address + '\'' +
                    ", status=" + status +
                    ", startTime=" + startTime +
                    ", roundId=" + roundId +
                    ", roundName='" + roundName + '\'' +
                    ", roundSonName='" + roundSonName + '\'' +
                    ", bo=" + bo +
                    ", 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 setAddress(String address) {
            this.address = address;
        }
 
        public void setStatus(int status) {
            this.status = status;
        }
 
        public void setStartTime(long startTime) {
            this.startTime = startTime;
        }
 
        public void setRoundId(long roundId) {
            this.roundId = roundId;
        }
 
        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 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=4109, leagueId=686, address='成都', status=0, startTime=1573387200000, roundId=314, roundName='常规赛', roundSonName='第九周', bo=5, teamAScore=0, teamAId=643, teamBScore=0, teamBid=884}
Match{matchId=4108, leagueId=686, address='上海', status=0, startTime=1573380000000, roundId=314, roundName='常规赛', roundSonName='第九周', bo=5, teamAScore=0, teamAId=699, teamBScore=0, teamBid=698}
Match{matchId=4107, leagueId=686, address='上海', status=0, startTime=1573369200000, roundId=314, roundName='常规赛', roundSonName='第九周', bo=5, teamAScore=0, teamAId=888, teamBScore=0, teamBid=696}
Match{matchId=4106, leagueId=686, address='成都', status=0, startTime=1573300800000, roundId=314, roundName='常规赛', roundSonName='第九周', bo=5, teamAScore=0, teamAId=685, teamBScore=0, teamBid=642}
Match{matchId=4100, leagueId=686, address='上海', status=0, startTime=1573293600000, roundId=314, roundName='常规赛', roundSonName='第九周', bo=5, teamAScore=0, teamAId=690, teamBScore=0, teamBid=692}

相关推荐
篮球比赛动画直播数据api接口示例
足球数据API接口 - 【比赛动画直播数据】API调用示例代码
国内体育数据提供商哪家强?一文为你清楚全解析