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

野子电竞数据官网改版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 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 matchList;

    @XmlElement(name = "match")
    public List getMatchList() {
        return matchList;
    }

    public void setMatchList(List 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;
    }
}

}

你可能感兴趣的:(objective-c,shell,html,php)