当前位置: 首页 > 后端技术 > PHP

如何获取足球【赛事联赛信息】数据

时间:2023-03-29 15:24:49 PHP

野子电竞数据官网改版https://www.xxe.io/全新登场importjavax.xml.bind.JAXBContext;importjavax.xml.bind.Unmarshaller;importjavax.xml.bind.annotation.XmlElement;importjavax.xml.bind.annotation.XmlRootElement;导入java.io.ByteArrayInputStream;导入java.nio.charset.StandardCharsets;导入java.nio.file.Files;导入java.nio.file.Paths;导入java.util.List;/**@API:5.联赛信息@Website:https://www.xxe.io/*/publicclassFootballLeagueInfo{publicstaticvoidmain(String[]args){try{Stringcontent=getContent();JAXBContextjaxbContext=JAXBContext.newInstance(LeagueList.class);解组器unmarshaller=jaxbContext.createUnmarshaller();LeagueListleagueList=(LeagueList)unmarshaller.unmarshal(newByteArrayInputStream(content.getBytes()));项目->System.out.println(项目));}catch(Throwablet){t.printStackTrace();}}/***获取API返回的内容**注意:这里为了测试文档方便,我这里使用了本地副本,使用时应替换为真正的接口返回内容*/privatestaticStringgetContent(){try{StringBuilderbuilder=newStringBuilder();Listlines=Files.readAllLines(Paths.get("./src/main/resources/FootballLeagueInfo.xml"),StandardCharsets.UTF_8);lines.forEach(line->builder.append(line));返回builder.toString();}catch(Throwablet){t.printStackTrace();返回””;}}@XmlRootElement(name="list")publicstaticclassLeagueList{@XmlElement(name="match")privateListleagueList;publicListgetLeagueList(){返回leagueList;}}@XmlRootElementpublicstaticclassLeague{@XmlElementprivateStringid;@XmlElement私有字符串gb_short;@XmlElement私有字符串big_short;@XmlElement私有字符串en_short;@XmlElement私有字符串gb;@XmlElement私有字符串大;@XmlElementprivateStringzh;@XmlElementprivateint类型;@XmlElement私有字符串子类;@XmlElementprivateintsum_round;@XmlElementprivateintcurr_round;@XmlElement私有字符串Curr_matchSeason;@XmlElement私有字符串countryID;@XmlElement私有字符串国家;@XmlElementprivateStringareaID;@XmlElementprivateStringcountryEn;@XmlElement私有字符串标识;@XmlElement私有字符串countryLogo;@OverridepublicStringtoString(){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+'\''+'}';}publicStringgetId(){返回ID;}publicStringgetGb_short(){返回gb_short;}publicStringgetBig_short(){返回big_short;}publicStringgetEn_short(){返回en_short;}publicStringgetGb(){返回gb;}publicStringgetBig(){返回大;}publicStringgetEn(){返回en;}publicintgetType(){返回类型;}publicStringgetSubSclass(){返回子类;}公共整数getSum_round(){返回sum_round;}publicintgetCurr_round(){返回curr_round;}publicStringgetCurr_matchSeason(){returnCurr_matchSeason;}publicStringgetCountryID(){返回国家ID;}publicStringgetCountry(){返回国家;}publicStringgetAreaID(){返回areaID;}publicStringgetCountryEn(){returncountryEn;}publicStringgetLogo(){返回标识;}publicStringgetCountryLogo(){返回countryLogo;}}}