如何获取足球【比赛联赛资料】数据

野子电竞数据官网改版 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: 5.比赛联赛资料
  • @Website: https://www.xxe.io/

*/

public class FootballLeagueInfo {

public static void main(String[] args) {
    try {
        String content = getContent();

        JAXBContext jaxbContext = JAXBContext.newInstance(LeagueList.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

        LeagueList leagueList = (LeagueList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
        leagueList.getLeagueList().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/FootballLeagueInfo.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 LeagueList {
    @XmlElement(name = "match")
    private List<League> leagueList;

    public List<League> getLeagueList() {
        return leagueList;
    }
}

@XmlRootElement
public static class League {
    @XmlElement
    private String id;
    @XmlElement
    private String gb_short;
    @XmlElement
    private String big_short;
    @XmlElement
    private String en_short;
    @XmlElement
    private String gb;
    @XmlElement
    private String big;
    @XmlElement
    private String en;
    @XmlElement
    private int type;
    @XmlElement
    private String subSclass;
    @XmlElement
    private int sum_round;
    @XmlElement
    private int curr_round;
    @XmlElement
    private String Curr_matchSeason;
    @XmlElement
    private String countryID;
    @XmlElement
    private String country;
    @XmlElement
    private String areaID;
    @XmlElement
    private String countryEn;
    @XmlElement
    private String logo;
    @XmlElement
    private String countryLogo;

    @Override
    public String toString() {
        return "League{" +
                "id='" + id + '/'' +
                ", gb_short='" + gb_short + '/'' +
                ", big_short='" + big_short + '/'' +
                ", en_short='" + en_short + '/'' +
                ", gb='" + gb + '/'' +
                ", big='" + big + '/'' +
                ", en='" + en + '/'' +
                ", type=" + type +
                ", subSclass='" + subSclass + '/'' +
                ", sum_round=" + sum_round +
                ", curr_round=" + curr_round +
                ", Curr_matchSeason='" + Curr_matchSeason + '/'' +
                ", countryID='" + countryID + '/'' +
                ", country='" + country + '/'' +
                ", areaID='" + areaID + '/'' +
                ", countryEn='" + countryEn + '/'' +
                ", logo='" + logo + '/'' +
                ", countryLogo='" + countryLogo + '/'' +
                '}';
    }

    public String getId() {
        return id;
    }

    public String getGb_short() {
        return gb_short;
    }

    public String getBig_short() {
        return big_short;
    }

    public String getEn_short() {
        return en_short;
    }

    public String getGb() {
        return gb;
    }

    public String getBig() {
        return big;
    }

    public String getEn() {
        return en;
    }

    public int getType() {
        return type;
    }

    public String getSubSclass() {
        return subSclass;
    }

    public int getSum_round() {
        return sum_round;
    }

    public int getCurr_round() {
        return curr_round;
    }

    public String getCurr_matchSeason() {
        return Curr_matchSeason;
    }

    public String getCountryID() {
        return countryID;
    }

    public String getCountry() {
        return country;
    }

    public String getAreaID() {
        return areaID;
    }

    public String getCountryEn() {
        return countryEn;
    }

    public String getLogo() {
        return logo;
    }

    public String getCountryLogo() {
        return countryLogo;
    }
}

}

原文 

https://segmentfault.com/a/1190000020191383

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

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

转载请注明原文出处:Harries Blog™ » 如何获取足球【比赛联赛资料】数据

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

评论 0

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