转载

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

野子电竞数据官网改版 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
正文到此结束
Loading...