足球数据API接口 - 【赛程赛果】API调用示例代码

以下是足球【赛程赛果】示例代码及返回数据,调用接口地址,需注册下

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
 
/**
 * @API: 4.赛程赛果
 * @Website: https://www.feijing88.com
 */
public class FootballResult {
 
    public static void main(String[] args) {
        try {
            String content = getContent();
 
            JAXBContext jaxbContext = JAXBContext.newInstance(MatchList.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
 
            MatchList matchList = (MatchList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
            matchList.getMatchList().forEach(item -> System.out.println(item));
 
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
 
    /**
     * 获取API返回内容
     *
     * Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
     */
    private static String getContent() {
        try {
            StringBuilder builder = new StringBuilder();
            List<String> lines = Files.readAllLines(Paths.get("./src/main/resources/FootballResult.xml"), StandardCharsets.UTF_8);
            lines.forEach(line -> builder.append(line));
            return builder.toString();
        } catch (Throwable t) {
            t.printStackTrace();
            return "";
        }
    }
 
    @XmlRootElement(name = "list")
    public static class MatchList {
        private List<Match> matchList;
 
        @XmlElement(name = "match")
        public List<Match> getMatchList() {
            return matchList;
        }
 
        public void setMatchList(List<Match> matchList) {
            this.matchList = matchList;
        }
    }
 
    @XmlRootElement
    public static class Match{
        @XmlElement(name = "a")
        private int matchId;
        @XmlElement(name = "c")
        private String leagueInfo;
        @XmlElement(name = "d")
        private String matchTime;
        @XmlElement(name = "e")
        private int subType;
        @XmlElement(name = "f")
        private int matchStatus;
        @XmlElement(name = "h")
        private String homeTeamInfo;
        @XmlElement(name = "i")
        private String awayTeamInfo;
        @XmlElement(name = "j")
        private int homeScore;
        @XmlElement(name = "k")
        private int awayScore;
        @XmlElement(name = "l")
        private int homeScoreFirstHalf;
        @XmlElement(name = "m")
        private int awayScroeFirstHalf;
        @XmlElement(name = "n")
        private int homeRed;
        @XmlElement(name = "o")
        private int awayRed;
        @XmlElement(name = "p")
        private int homeRank;
        @XmlElement(name = "q")
        private int awayRank;
        @XmlElement(name = "s")
        private String round;
        @XmlElement(name = "t")
        private String address;
        @XmlElement(name = "x")
        private String season;
        @XmlElement(name = "y")
        private String group;
        @XmlElement(name = "z")
        private String isNeutral;
        @XmlElement(name = "subID")
        private String subLeagueId;
        @XmlElement(name = "yellow")
        private int yellow;
 
        @Override
        public String toString() {
            return "Match{" +
                    "matchId=" + matchId +
                    ", leagueInfo='" + leagueInfo + '\'' +
                    ", matchTime='" + matchTime + '\'' +
                    ", subType=" + subType +
                    ", matchStatus=" + matchStatus +
                    ", homeTeamInfo='" + homeTeamInfo + '\'' +
                    ", awayTeamInfo='" + awayTeamInfo + '\'' +
                    ", homeScore=" + homeScore +
                    ", awayScore=" + awayScore +
                    ", homeScoreFirstHalf=" + homeScoreFirstHalf +
                    ", awayScroeFirstHalf=" + awayScroeFirstHalf +
                    ", homeRed=" + homeRed +
                    ", awayRed=" + awayRed +
                    ", homeRank=" + homeRank +
                    ", awayRank=" + awayRank +
                    ", round='" + round + '\'' +
                    ", address='" + address + '\'' +
                    ", season='" + season + '\'' +
                    ", group='" + group + '\'' +
                    ", isNeutral='" + isNeutral + '\'' +
                    ", subLeagueId='" + subLeagueId + '\'' +
                    ", yellow=" + yellow +
                    '}';
        }
 
        public int getMatchId() {
            return matchId;
        }
 
        public String getLeagueInfo() {
            return leagueInfo;
        }
 
        public String getMatchTime() {
            return matchTime;
        }
 
        public int getSubType() {
            return subType;
        }
 
        public int getMatchStatus() {
            return matchStatus;
        }
 
        public String getHomeTeamInfo() {
            return homeTeamInfo;
        }
 
        public String getAwayTeamInfo() {
            return awayTeamInfo;
        }
 
        public int getHomeScore() {
            return homeScore;
        }
 
        public int getAwayScore() {
            return awayScore;
        }
 
        public int getHomeScoreFirstHalf() {
            return homeScoreFirstHalf;
        }
 
        public int getAwayScroeFirstHalf() {
            return awayScroeFirstHalf;
        }
 
        public int getHomeRed() {
            return homeRed;
        }
 
        public int getAwayRed() {
            return awayRed;
        }
 
        public int getHomeRank() {
            return homeRank;
        }
 
        public int getAwayRank() {
            return awayRank;
        }
 
        public String getRound() {
            return round;
        }
 
        public String getAddress() {
            return address;
        }
 
        public String getSeason() {
            return season;
        }
 
        public String getGroup() {
            return group;
        }
 
        public String getIsNeutral() {
            return isNeutral;
        }
 
        public String getSubLeagueId() {
            return subLeagueId;
        }
 
        public int getYellow() {
            return yellow;
        }
    }
}

返回数据如下:

Match{matchId=1720912, leagueInfo='英超,英超,ENG PR,36,1', matchTime='2019/8/10 3:00:00', subType=0, matchStatus=0, homeTeamInfo='利物浦,利物浦,Liverpool,25', awayTeamInfo='诺维奇,諾域治,Norwich City,34', homeScore=0, awayScore=0, homeScoreFirstHalf=0, awayScroeFirstHalf=0, homeRed=0, awayRed=0, homeRank=0, awayRank=0, round='1', address='', season='2019-2020', group='', isNeutral='False', subLeagueId='', yellow=0}
Match{matchId=1720911, leagueInfo='英超,英超,ENG PR,36,1', matchTime='2019/8/10 19:30:00', subType=0, matchStatus=0, homeTeamInfo='西汉姆联,韋斯咸,West Ham United,62', awayTeamInfo='曼彻斯特城,曼城,Manchester City,26', homeScore=0, awayScore=0, homeScoreFirstHalf=0, awayScroeFirstHalf=0, homeRed=0, awayRed=0, homeRank=0, awayRank=0, round='1', address='', season='2019-2020', group='', isNeutral='False', subLeagueId='', yellow=0}
Match{matchId=1720906, leagueInfo='英超,英超,ENG PR,36,1', matchTime='2019/8/10 22:00:00', subType=0, matchStatus=0, homeTeamInfo='沃特福德,屈福特,Watford,53', awayTeamInfo='布莱顿,白禮頓,Brighton Hove Albion,60', homeScore=0, awayScore=0, homeScoreFirstHalf=0, awayScroeFirstHalf=0, homeRed=0, awayRed=0, homeRank=0, awayRank=0, round='1', address='', season='2019-2020', group='', isNeutral='False', subLeagueId='', yellow=0}
Match{matchId=1720908, leagueInfo='英超,英超,ENG PR,36,1', matchTime='2019/8/10 22:00:00', subType=0, matchStatus=0, homeTeamInfo='伯恩茅斯,般尼茅夫,Bournemouth AFC,348', awayTeamInfo='谢菲尔德联队,錫菲聯,Sheffield United,51', homeScore=0, awayScore=0, homeScoreFirstHalf=0, awayScroeFirstHalf=0, homeRed=0, awayRed=0, homeRank=0, awayRank=0, round='1', address='', season='2019-2020', group='', isNeutral='False', subLeagueId='', yellow=0}
Match{matchId=1720909, leagueInfo='英超,英超,ENG PR,36,1', matchTime='2019/8/10 22:00:00', subType=0, matchStatus=0, homeTeamInfo='伯恩利,般尼,Burnley,46', awayTeamInfo='南安普敦,修咸頓,Southampton,30', homeScore=0, awayScore=0, homeScoreFirstHalf=0, awayScroeFirstHalf=0, homeRed=0, awayRed=0, homeRank=0, awayRank=0, round='1', address='', season='2019-2020', group='', isNeutral='False', subLeagueId='', yellow=0}
Match{matchId=1720910, leagueInfo='英超,英超,ENG PR,36,1', matchTime='2019/8/10 22:00:00', subType=0, matchStatus=0, homeTeamInfo='水晶宫,水晶宮,Crystal Palace,35', awayTeamInfo='埃弗顿,愛華頓,Everton,31', homeScore=0, awayScore=0, homeScoreFirstHalf=0, awayScroeFirstHalf=0, homeRed=0, awayRed=0, homeRank=0, awayRank=0, round='1', address='', season='2019-2020', group='', isNeutral='False', subLeagueId='', yellow=0}

相关推荐
电竞助力体育数据新发展,飞鲸体育紧跟潮流趋势
便于格式化和清洗数据的Python工具包合集
一文了解电竞大数据平台的系统架构演进