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

篮球数据API接口-【实时比分数据】API调用示例代码

时间:2023-03-30 00:30:22 PHP

野子电竞数据官网改版https://www.xxe.io/全新登陆packagecom.huaying.demo.basketball;importjavax.xml.bind.JAXBContext;importjavax.xml.bind.Unmarshaller;importjavax.xml.bind.annotation.XmlElement;导入javax.xml.bind.annotation.XmlRootElement;导入java.io.ByteArrayInputStream;导入java.nio.charset.StandardCharsets;导入java.nio.file.Files;导入java.nio.file。Paths;importjava.util.List;importjava.util.stream.Collectors;/**@API:2.即时变化的比分数据@Website:https://www.xxe.io/*/publicclassBasketballChange{publicstaticvoidmain(String[]args){try{Stringcontent=getContent();JAXBContextjaxbContext=JAXBContext.newInstance(ChangeList.class);解组器unmarshaller=jaxbContext.createUnmarshaller();ChangeList列表=(ChangeList)unmarshaller.unmarshal(newByteArrayInputStream(content.getBytes()));list.getChangeList().forEach(System.out::println);}catch(Throwablet){t.printStackTrace();}}/***获取API返回的内容*

*注意:这里为了测试方便,使用了本地文件,需要替换为真实接口的返回内容*/privatestaticStringgetContent(){尝试{StringBuilder构建器=newStringBuilder();Listlines=Files.readAllLines(Paths.get("./src/main/resources/BasketballChange.xml"),StandardCharsets.UTF_8);lines.forEach(line->builder.append(line));返回builder.toString();}catch(Throwablet){t.printStackTrace();返回””;}}@XmlRootElement(name="c")publicstaticclassChangeList{@XmlElement(name="h")privateListitemList;publicListgetChangeList(){返回itemList。溪流()。map(s->{Changechange=newChange();change.parse(s);returnchange;}).collect(Collectors.toList());}}publicstaticclassChange{privateStringmatchId;私人诠释匹配状态;私有字符串剩余时间;私有整数主场得分;私人inthomeScoreFirst;私人inthomeScoreSecond;私人inthomeScoreThird;私人inthomeScoreFourth;privateinthomeScoreFirstOT;私人inthomeScoreSecondOT;私人inthomeScoreThirdOT;私人诠释awayScore;privateintawayScoreFirst;私人诠释awayScoreSecond;私人诠释awayScoreThird;私人诠释awayScoreFourth;privateintawayScoreFirstOT;私人诠释awayScoreSecondOT;私人诠释awayScoreThirdOT;publicvoidparse(Stringdata){String[]values=data.split("\\^");matchId=值[0];matchStatus=parseInt(值[1]);剩余时间=值[2];homeScore=parseInt(值[3]);homeScoreFirst=parseInt(值[5]);homeScoreSecond=parseInt(值[7]);homeScoreThird=parseInt(值[9]);homeScoreFourth=parseInt(值[11]);homeScoreFirstOT=parseInt(值[16]);homeScore秒ondOT=parseInt(值[18]);homeScoreThirdOT=parseInt(值[20]);awayScore=parseInt(值[4]);awayScoreFirst=parseInt(值[6]);awayScoreSecond=parseInt(值[8]);awayScoreThird=parseInt(值[10]);awayScoreFourth=parseInt(值[12]);awayScoreFirstOT=parseInt(值[17]);awayScoreSecondOT=parseInt(值[19]);awayScoreThirdOT=parseInt(值[21]);}privateintparseInt(Stringdata){返回数据==null||数据.isEmpty()?0:Integer.valueOf(数据);}@OverridepublicStringtoString(){return"Change{"+"matchId='"+matchId+'\''+",matchStatus="+matchStatus+",remainTime='"+remainTime+'\''+",homeScore="+homeScore+",homeScoreFirst="+homeScoreFirst+",homeScoreSecond="+homeScoreSecond+",homeScoreThird="+homeScoreThird+",homeScoreFourth="+homeScoreFourth+",homeScoreFirstOT="+homeScoreFirstOT+",homeScoreSecondOT="+homeScoreSecondOT+",homeScoreThirdOT="+homeScoreThirdOT+",awayScore="+awayScore+",awayScoreFirst="+awayScoreFirst+",awayScoreSecond="+awayScoreSecond+",awayScoreThird="+awayScoreThird+",awayScoreFourth="+awayScoreFourth+",awayScoreFirstOT="+awayScoreFirstOT+",awayScoreSecondOT="+awayScoreSecondOT+",awayScoreThirdOT="+awayScoreThirdOT+'}';}}}

最新推荐
猜你喜欢