分享API接口调用示例代码,可查看在线调用文档,需要注册https://www.feijing88.com/bas...packagecom.huaying.demo.basketball;导入javax.xml.bind。JAXBContext;导入javax.xml.bind.Unmarshaller;导入javax.xml.bind.annotation.XmlElement;导入javax.xml.bind.annotation.XmlRootElement;导入java.io.ByteArrayInputStream;导入java.nio.charset.StandardCharsets;导入java.nio.file.Files;导入java.nio.file.Paths;导入java.util.List;导入java.util.stream.Collectors;/***@API:2.立即更改得分数据*@Website:https://www.feijing88.com*/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(){returnitemList.stream().map(s->{Changechange=newChange();change.parse(s);}退回零钱;}).collect(Collectors.toList());}}publicstaticclassChange{privateStringmatchId;私人诠释匹配状态;私有字符串剩余时间;私人inthomeScore;私人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]);homeScoreSecondOT=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+'}';}}}API返回数据如下(部分):Change{matchId='358749',matchStatus=-1,remainTime='',homeScore=86,homeScoreFirst=28,homeScoreSecond=22,homeScoreThird=13,homeScoreFourth=23,homeScoreFirstOT=0,homeScoreSecondOT=0,homeScoreThirdOT=0,awayScore=52,awayScoreFirst=20,awayScoreSecond=11,awayScoreThird=14,awayScoreFourth=7,awayScoreFirstOT=0,awayScoreSecondOT=0,awayScoreThirdOT=0}更改{matchId='358761',matchStatus=2,remainTime='06:50',homeScore=20,homeScoreFirst=14,homeScoreSecond=6,homeScoreThird=0,homeScoreFourth=0,homeScoreFirstOT=0,homeScoreSecondOT=0,homeScoreThirdOT=0,awayScore=44,awayScoreFirst=31,awayScoreSecond=13,awayScoreThird=0,awayScoreFourth=0,awayScoreFirstOT=0,awayScoreSecondOT=0,awayScoreThirdOT=0}