篮球即时比分api接口调用示例代码

简介: 篮球即时比分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;
import java.util.stream.Collectors;
 
/**
 * @API: 2.即时变化的比分数据
 * @Website: https://www.feijing88.com
 */
public class BasketballChange {
 
    public static void main(String[] args) {
        try {
            String content = getContent();
 
            JAXBContext jaxbContext = JAXBContext.newInstance(ChangeList.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
 
            ChangeList list = (ChangeList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
            list.getChangeList().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/BasketballChange.xml"), StandardCharsets.UTF_8);
            lines.forEach(line -> builder.append(line));
            return builder.toString();
        } catch (Throwable t) {
            t.printStackTrace();
            return "";
        }
    }
 
 
    @XmlRootElement(name = "c")
    public static class ChangeList {
        @XmlElement(name = "h")
        private List<String> itemList;
 
        public List<Change> getChangeList() {
            return itemList.stream().map(s -> {
                Change change = new Change();
                change.parse(s);
                return change;
            }).collect(Collectors.toList());
        }
    }
 
    public static class Change {
        private String matchId;
        private int matchStatus;
        private String remainTime;
        private int homeScore;
        private int homeScoreFirst;
        private int homeScoreSecond;
        private int homeScoreThird;
        private int homeScoreFourth;
        private int homeScoreFirstOT;
        private int homeScoreSecondOT;
        private int homeScoreThirdOT;
        private int awayScore;
        private int awayScoreFirst;
        private int awayScoreSecond;
        private int awayScoreThird;
        private int awayScoreFourth;
        private int awayScoreFirstOT;
        private int awayScoreSecondOT;
        private int awayScoreThirdOT;
 
        public void parse(String data) {
            String[] values = data.split("\\^");
            matchId = values[0];
            matchStatus = parseInt(values[1]);
            remainTime = values[2];
            homeScore = parseInt(values[3]);
            homeScoreFirst = parseInt(values[5]);
            homeScoreSecond = parseInt(values[7]);
            homeScoreThird = parseInt(values[9]);
            homeScoreFourth = parseInt(values[11]);
            homeScoreFirstOT = parseInt(values[16]);
            homeScoreSecondOT = parseInt(values[18]);
            homeScoreThirdOT = parseInt(values[20]);
            awayScore = parseInt(values[4]);
            awayScoreFirst = parseInt(values[6]);
            awayScoreSecond = parseInt(values[8]);
            awayScoreThird = parseInt(values[10]);
            awayScoreFourth = parseInt(values[12]);
            awayScoreFirstOT = parseInt(values[17]);
            awayScoreSecondOT = parseInt(values[19]);
            awayScoreThirdOT = parseInt(values[21]);
        }
 
        private int parseInt(String data) {
            return data == null || data.isEmpty() ? 0 : Integer.valueOf(data);
        }
 
        @Override
        public String toString() {
            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='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}
相关文章
|
7月前
|
人工智能 Java API
Google Gemini API 接口调用方法
Google 最近发布的 Gemini 1.0 AI 模型通过其升级版,Gemini,标志着公司迄今为止最为强大和多功能的人工智能技术的突破。
|
24天前
|
JSON API 开发者
淘系买家秀API接口系列,示例代码返回值说明
淘宝买家秀API接口是阿里巴巴旗下的淘宝平台提供的一种接口服务,允许淘宝商家或开发者通过编程方式获取并展示淘宝商品的买家秀信息,包括买家上传的图片、视频、评论等内容。以下是对淘宝买家秀API接口的详细介绍:
|
5月前
|
Java API PHP
【亲测有效,官方提供】php版本企查查api接口请求示例代码,php请求企查查api接口,thinkphp请求企查查api接口
【亲测有效,官方提供】php版本企查查api接口请求示例代码,php请求企查查api接口,thinkphp请求企查查api接口
170 1
|
5月前
|
监控 搜索推荐 Java
​邮件群发API,AOKSend关于Java示例代码
AOKSend邮件群发API简化了企业邮件自动化,提高效率,支持个性化内容和实时分析。其优势在于易于集成、高可靠性、丰富功能和详细统计。Java开发者可快速添加依赖,配置API密钥,使用示例代码发送邮件。通过AOKSend,企业能优化邮件策略,提升邮件营销效果。
|
5月前
|
API PHP 开发者
​邮件发送API示例代码,AOKSend关于PHP示例代码
**邮件发送API简化了开发中的邮件功能,如自动化通知和营销邮件。常见示例包括SendGrid和Mailgun的Python代码。AOKSend在PHP中的使用示例展示了如何使用Guzzle库发送邮件,其特点包括高可靠性、易于集成和强大功能。通过API,开发者能高效、可靠地发送大规模邮件。**
|
6月前
|
API 开发工具
企业微信api接口调用-触发企业微信推送会话列表
企业微信api接口调用-触发企业微信推送会话列表
|
6月前
|
API 开发工具
企业微信api接口调用-通过手机号或微信好友添加客户
企业微信api接口调用-通过手机号或微信好友添加客户
|
6月前
|
API 开发工具
企业微信api接口调用-触发推送企业微信联系人列表
企业微信api接口调用-触发推送企业微信联系人列表
|
6月前
|
API 开发工具
企业微信api接口调用-触发推送企业微信微信好友
企业微信api接口调用-触发推送企业微信微信好友
|
6月前
|
API
企业微信api接口调用-企业微信好友收发消息
企业微信api接口调用-企业微信好友收发消息
下一篇
DataWorks