籃球聯賽數據api示例

分享之前調用過的體育數據api,可註冊使用下籃球聯賽數據,在線文檔

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.feijing88.com
 */
public class BasketballLeagueInfo {
 
    public static void main(String[] args) {
        try {
            String content = getContent();
 
            JAXBContext jaxbContext = JAXBContext.newInstance(LeagueList.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
 
            LeagueList list = (LeagueList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
            list.getLeagueList().forEach(System.out::println);
 
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
 
    /**
     * 獲取API返回內容
     * <p>
     * Note: 這裏爲了方便測試我使用了一份本地文件,使用時應替換爲真實接口返回內容
     */
    private static String getContent() {
        try {
            StringBuilder builder = new StringBuilder();
            List<String> lines = Files.readAllLines(Paths.get("./src/main/resources/BasketballLeagueInfo.xml"), StandardCharsets.UTF_8);
            lines.forEach(builder::append);
            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;
        }
    }
 
    public static class League {
        @XmlElement(name = "id")
        private String id;
        @XmlElement(name = "short")
        private String nameShort;
        @XmlElement(name = "gb")
        private String nameGb;
        @XmlElement(name = "big")
        private String nameBig;
        @XmlElement(name = "en")
        private String nameEn;
        @XmlElement(name = "type")
        private int type;
        @XmlElement(name = "Curr_matchSeason")
        private String currentSeason;
        @XmlElement(name = "countryID")
        private String countryId;
        @XmlElement(name = "country")
        private String countryName;
        @XmlElement(name = "curr_year")
        private int currentYear;
        @XmlElement(name = "curr_month")
        private int currentMonth;
        @XmlElement(name = "sclass_kind")
        private int kind;
 
        @Override
        public String toString() {
            return "League{" +
                    "id='" + id + '\'' +
                    ", nameShort='" + nameShort + '\'' +
                    ", nameGb='" + nameGb + '\'' +
                    ", nameBig='" + nameBig + '\'' +
                    ", nameEn='" + nameEn + '\'' +
                    ", type=" + type +
                    ", currentSeason='" + currentSeason + '\'' +
                    ", countryId='" + countryId + '\'' +
                    ", countryName='" + countryName + '\'' +
                    ", currentYear=" + currentYear +
                    ", currentMonth=" + currentMonth +
                    ", kind=" + kind +
                    '}';
        }
    }
}

API 返回數據如下(部分):

League{id='2', nameShort='WNBA', nameGb='美國女子職業籃球聯賽', nameBig='美國女子職業籃球聯賽', nameEn='Women’s National Basketball Association', type=4, currentSeason='19', countryId='1', countryName='美國', currentYear=2011, currentMonth=9, kind=1}
League{id='3', nameShort='斯坦杯', nameGb='斯坦科維奇洲際冠軍盃', nameBig='斯坦科域治洲際冠軍盃', nameEn='Stank Vic Basketball Champions LeagueChampions Cup', type=4, currentSeason='18', countryId='20', countryName='國際賽事', currentYear=2011, currentMonth=8, kind=2}
League{id='5', nameShort='CBA', nameGb='中國男子籃球聯賽', nameBig='中國男子籃球聯賽', nameEn='Chinese Basketball Association', type=4, currentSeason='18-19', countryId='2', countryName='中國', currentYear=2011, currentMonth=11, kind=1}
League{id='7', nameShort='Euro', nameGb='歐洲籃球冠軍聯賽', nameBig='歐洲籃球冠軍聯賽', nameEn='EURO', type=4, currentSeason='19-20', countryId='16', countryName='歐洲賽事', currentYear=2011, currentMonth=10, kind=2}
League{id='8', nameShort='NCAA', nameGb='美國大學男子籃球聯賽', nameBig='美國大學男子籃球聯賽', nameEn='National Committee Association America', type=2, currentSeason='18-19', countryId='1', countryName='美國', currentYear=2009, currentMonth=11, kind=1}
League{id='9', nameShort='女南錦U17', nameGb='南美洲女子籃球錦標賽U17', nameBig='女南錦U17', nameEn='FIBA Sudamericano Femenino U17', type=4, currentSeason='17', countryId='18', countryName='美洲賽事', currentYear=2011, currentMonth=6, kind=2}
League{id='10', nameShort='籃世杯', nameGb='籃球世界盃', nameBig='籃球世界盃', nameEn='FIBA Basketball World Cup', type=4, currentSeason='19', countryId='20', countryName='國際賽事', currentYear=2010, currentMonth=8, kind=2}
League{id='13', nameShort='世女俱', nameGb='世女俱', nameBig='世女俱', nameEn='The world women Club', type=4, currentSeason='17', countryId='20', countryName='國際賽事', currentYear=2007, currentMonth=10, kind=2}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章