篮球数据API接口 - 【即时指数2】API调用示例代码

分享使用 飞鲸体育数据 www.feijing88.com 接口调用的示例代码,篮球指数【即时指数2】接口

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: 11.百家欧赔接口
 * @Website: https://www.feijing88.com
 */
public class BasketballOdds100 {

    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/BasketballBet100.xml"), StandardCharsets.UTF_8);
            lines.forEach(line -> builder.append(line));
            return builder.toString();
        } catch (Throwable t) {
            t.printStackTrace();
            return "";
        }
    }

    @XmlRootElement(name = "c")
    public static class MatchList {
        private List matchList;

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

        public void setMatchList(List matchList) {
            this.matchList = matchList;
        }
    }

    public static class Match{
        @XmlElement(name = "id")
        private String matchId;
        @XmlElement(name = "time")
        private String matchTime;
        @XmlElement(name = "league")
        private String leagueName;
        @XmlElement(name = "home")
        private String homeTeamName;
        @XmlElement(name = "away")
        private String awayTeamName;
        @XmlElement(name = "odds")
        private List oddsList;

        @Override
        public String toString() {
            return "Match{" +
                    "matchId='" + matchId + '\'' +
                    ", matchTime='" + matchTime + '\'' +
                    ", leagueName='" + leagueName + '\'' +
                    ", homeTeamName='" + homeTeamName + '\'' +
                    ", awayTeamName='" + awayTeamName + '\'' +
                    ", oddsList=" + oddsList +
                    '}';
        }

        public String getMatchId() {
            return matchId;
        }

        public String getMatchTime() {
            return matchTime;
        }

        public String getLeagueName() {
            return leagueName;
        }

        public String getHomeTeamName() {
            return homeTeamName;
        }

        public String getAwayTeamName() {
            return awayTeamName;
        }

        public List getOddsList() {
            return oddsList;
        }
    }

    private static class Odds{
        @XmlElement(name = "o")
        private String item;

        @Override
        public String toString() {
            return "Odds{" +
                    "item='" + item + '\'' +
                    '}';
        }

        public String getItem() {
            return item;
        }
    }
}

API 返回数据如下(部分): 

Match{matchId='358894', matchTime='2019/8/2 17:00:00', leagueName='WNBL1,澳洲女子NBL1,澳洲女子NBL1', homeTeamName='Bendigo Spirit Women's,賓迪高精靈女籃,本迪高精灵女篮', awayTeamName='Kilsyth Cobras (W),基爾塞斯眼鏡蛇女籃,基尔塞斯眼镜蛇女篮', oddsList=[Odds{item='6,Easybets,1.04,8.4,1.06,6.4,2019/8/2 16:59:46,6855229'}]}
Match{matchId='359772', matchTime='2019/8/2 18:00:00', leagueName='FC,友誼賽,友谊赛', homeTeamName='Toowoomba Mountaineers,圖文巴登山者,图文巴登山者', awayTeamName='Brisbane Spartans,布里斯班斯巴達人,布里斯班斯巴达人', oddsList=[Odds{item='560,1xBet,2.77,1.42,2.78,1.41,2019/8/2 17:01:05,6855244'}]}
Match{matchId='359415', matchTime='2019/8/2 19:00:00', leagueName='PBCC,菲專員盃,菲专员杯', homeTeamName='San Miguel Beermen,生力啤酒人,生力啤', awayTeamName='Rain or Shine Elasto Painters,陰陽天,伊拉斯图阴阳天', oddsList=[Odds{item='3,Interwetten,1.5,2.25,1.25,3.3,2019/8/2 17:02:57,6854945'}]}
Match{matchId='359388', matchTime='2019/8/3 3:30:00', leagueName='FC,友誼賽,友谊赛', homeTeamName='Spain,西班牙,西班牙', awayTeamName='Lithuania,立陶宛,立陶宛', oddsList=[Odds{item='82,Vcbet,1.286,3.4,1.2,4.2,2019/8/2 17:04:31,6855123'}]}
Match{matchId='359409', matchTime='2019/8/3 7:00:00', leagueName='PAGM,泛美運動會男子籃球賽,泛美运动会男子篮球赛', homeTeamName='Virgin Islands,美屬維京群島,美属维尔京群岛', awayTeamName='Venezuela,委內瑞拉,委内瑞拉', oddsList=[Odds{item='3,Interwetten,5,1.09,5,1.1,2019/8/2 17:04:06,6855302'}]}
Match{matchId='359410', matchTime='2019/8/3 10:00:00', leagueName='PAGM,泛美運動會男子籃球賽,泛美运动会男子篮球赛', homeTeamName='Puerto Rico,波多黎各,波多黎各', awayTeamName='USA,美國,美国', oddsList=[Odds{item='368,Sportingbet,5.5,1.11,5.5,1.11,2019/8/2 17:02:25,6855373'}]}

你可能感兴趣的:(篮球数据,篮球赔率)