如何获取足球【赛程结果】数据

野子电竞数据官网改版 https://www.xxe.io/
全新登场

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.xxe.io/

*/

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;
    }
}

}

原文 

https://segmentfault.com/a/1190000020202839

本站部分文章源于互联网,本着传播知识、有益学习和研究的目的进行的转载,为网友免费提供。如有著作权人或出版方提出异议,本站将立即删除。如果您对文章转载有任何疑问请告之我们,以便我们及时纠正。

PS:推荐一个微信公众号: askHarries 或者qq群:474807195,里面会分享一些资深架构师录制的视频录像:有Spring,MyBatis,Netty源码分析,高并发、高性能、分布式、微服务架构的原理,JVM性能优化这些成为架构师必备的知识体系。还能领取免费的学习资源,目前受益良多

转载请注明原文出处:Harries Blog™ » 如何获取足球【赛程结果】数据

赞 (0)
分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址