当前位置: 首页 > Web前端 > CSS

篮球数据API接口-【篮球运动员】API调用示例代码

时间:2023-03-31 01:48:09 CSS

野子电竞数据官网改版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:7.篮球运动员@Website:https://www.xxe.io/*/publicclassBasketballPlayerInfo{publicstaticvoidmain(String[]args){try{Stringcontent=getContent();JAXBContextjaxbContext=JAXBContext.newInstance(PlayerList.class);解组器unmarshaller=jaxbContext.createUnmarshaller();PlayerList列表=(PlayerList)unmarshaller.unmarshal(newByteArrayInputStream(content.getBytes()));list.getPlayerList().forEach(System.out::println);}catch(Throwablet){t.printStackTrace();}}/***获取API返回内容*

*注意:这里为了测试方便,我使用了本地文件,use应该换成真正的接口返回内容*/privatestaticStringgetContent(){try{StringBuilderbuilder=newStringBuilder();Listlines=Files.readAllLines(Paths.get("./src/main/resources/BasketballPlayerInfo.xml"),StandardCharsets.UTF_8);lines.forEach(builder::append);返回builder.toString();}catch(Throwablet){t.printStackTrace();返回””;}}@XmlRootElement(name="list")publicstaticclassPlayerList{@XmlElement(name="i")privateListplayerList;publicListgetPlayerList(){返回玩家列表;}}publicstaticclassPlayer{@XmlElement(name="id")privateStringid;@XmlElement(name="Number")私有字符串数字;@XmlElement(name="Name_F")privateStringnameBig;@XmlElement(name="Name_JS")privateStringnameGbShort;@XmlElement(name="Name_J")privateStringnameGb;@XmlElement(name="Name_E")私人海峡ingnameEn;@XmlElement(name="TeamID")privateStringteamId;@XmlElement(name="Place")私有字符串位置;@XmlElement(name="Birthday")privateStringbirthday;@XmlElement(name="Tallness")privateStringtallness;@XmlElement(name="Weight")私有字符串权重;@XmlElement(name="Photo")私有字符串照片;@XmlElement(name="NbaAge")privateStringnbaAge;@XmlElement(name="Salary")privateStringsalary;@OverridepublicStringtoString(){return"Player{"+"id='"+id+'\''+",number='"+number+'\''+",nameBig='"+nameBig+'\''+",nameGbShort='"+nameGbShort+'\''+",nameGb='"+nameGb+'\''+",nameEn='"+nameEn+'\''+",teamId='"+teamId+'\''+",place='"+place+'\''+",birthday='"+birthday+'\''+",tallness='"+tallness+'\''+",weight='"+weight+'\''+",photo='"+photo+'\''+",nbaAge='"+nbaAge+'\''+",salary='"+salary+'\''+'}';}}}