我是靠谱客的博主 要减肥猎豹,最近开发中收集的这篇文章主要介绍篮球数据API接口 - 【篮球球员库】API调用示例代码,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

分享使用接口调用的示例代码,篮球数据【篮球球员库】接口

import javax.xml.bind.JAXBContext;
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: 7.篮球球员库
*/
public class BasketballPlayerInfo {
public static void main(String[] args) {
try {
String content = getContent();
JAXBContext jaxbContext = JAXBContext.newInstance(PlayerList.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
PlayerList list = (PlayerList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
list.getPlayerList().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/BasketballPlayerInfo.xml"), StandardCharsets.UTF_8);
lines.forEach(builder::append);
return builder.toString();
} catch (Throwable t) {
t.printStackTrace();
return "";
}
}
@XmlRootElement(name = "list")
public static class PlayerList{
@XmlElement(name = "i")
private List<Player> playerList;
public List<Player> getPlayerList() {
return playerList;
}
}
public static class Player {
@XmlElement(name = "id")
private String id;
@XmlElement(name = "Number")
private String number;
@XmlElement(name = "Name_F")
private String nameBig;
@XmlElement(name = "Name_JS")
private String nameGbShort;
@XmlElement(name = "Name_J")
private String nameGb;
@XmlElement(name = "Name_E")
private String nameEn;
@XmlElement(name = "TeamID")
private String teamId;
@XmlElement(name = "Place")
private String place;
@XmlElement(name = "Birthday")
private String birthday;
@XmlElement(name = "Tallness")
private String tallness;
@XmlElement(name = "Weight")
private String weight;
@XmlElement(name = "Photo")
private String photo;
@XmlElement(name = "NbaAge")
private String nbaAge;
@XmlElement(name = "Salary")
private String salary;
@Override
public String toString() {
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 + ''' +
'}';
}
}
}

API 返回数据如下(部分): 

Player{id='4982', number='4', nameBig='艾西亞泰萊', nameGbShort='I.泰萊', nameGb='I.泰萊', nameEn='Isaiah Taylor', teamId='5264', place='后卫', birthday='1994/7/11 0:00:00', tallness='191', weight='77', photo='/files/Player/20161018165348.jpg', nbaAge='2', salary='131'}
Player{id='4983', number='40', nameBig='祖巴域', nameGbShort='伊维察-祖巴茨', nameGb='伊维察-祖巴茨', nameEn='Ivica Zubac', teamId='29', place='中锋', birthday='1997/3/18 0:00:00', tallness='216', weight='109', photo='/files/Player/20161018165918.jpg', nbaAge='3', salary='154'}
Player{id='4997', number='95', nameBig='賓布利', nameGbShort='本布里', nameGb='德安德鲁-本布里', nameEn='DeAndre Bembry', teamId='13', place='前锋', birthday='1994/7/4 0:00:00', tallness='198', weight='95', photo='/files/Player/20161010174225.jpg', nbaAge='3', salary='163'}
Player{id='4998', number='3', nameBig='Y.費尼爾', nameGbShort='费雷尔', nameGb='Y.费雷尔', nameEn='Yogi Ferrell', teamId='24', place='后卫', birthday='1993/5/9 0:00:00', tallness='183', weight='82', photo='/files/Player/20161206175607.jpg', nbaAge='3', salary='300'}
Player{id='5026', number='21', nameBig='C.奧奴亞古', nameGbShort='C·欧努阿库', nameGb='齐纳努·欧努阿库', nameEn='Chinanu Onuaku', teamId='64', place='前锋', birthday='1996/11/1 0:00:00', tallness='208', weight='111', photo='/files/Player/20161018165325.jpg', nbaAge='', salary=''}

最后

以上就是要减肥猎豹为你收集整理的篮球数据API接口 - 【篮球球员库】API调用示例代码的全部内容,希望文章能够帮你解决篮球数据API接口 - 【篮球球员库】API调用示例代码所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部