篮球即时比分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}
相关文章
|
2月前
|
XML API 数据格式
API商品数据接口调用实战
随着互联网技术的发展,应用程序间的数据交互变得越来越重要。API(Application Programming Interface,应用程序编程接口)作为一种标准化的数据交互方式,被广泛应用于各种场景。本文将围绕API商品数据接口调用进行实战探讨,涉及API的基本概念、商品数据接口的设计、接口调用实现以及代码示例等方面。
|
2月前
|
数据采集 Java API
Java爬虫实战:API商品数据接口调用
随着互联网的发展,越来越多的商家开始将自己的商品数据通过API接口对外开放,以供其他开发者使用。这些API接口可以提供丰富的商品数据,包括商品名称、价格、库存、图片等信息。对于Java爬虫开发者来说,通过调用这些API接口,可以更加便捷地获取商品数据,避免了爬取网页数据的繁琐过程。本文将介绍如何使用Java调用API商品数据接口,实现商品数据的获取和处理。
|
3月前
|
存储 缓存 小程序
【小程序开发必备】微信小程序常用API全介绍,附示例代码和使用场景
本篇博文介绍了微信小程序常用API,包括网络请求、数据缓存、交互反馈、设备、媒体、界面、开放接口等方面。每个API都附有详细的介绍和示例代码,以及使用场景。这些API可以帮助小程序开发者快速实现各种功能和交互效果,是小程序开发的必备工具。无论是初学者还是有一定经验的开发者,都能从本篇博文中学到很多实用的技巧和知识。
|
5月前
|
XML JSON API
深入了解API接口调用——从获取淘宝商品数据开始
API(Application Programming Interface)是现代软件开发中常用的一种技术,它允许不同的软件系统进行交互和通信。在本文中,我们将深入探讨如何通过API接口来获取淘宝商品数据。这是一个常见的需求,无论是对于商家还是开发者,都有着重要的意义。
|
6月前
|
XML JSON 缓存
lazada获得lazada商品详情 API接口调用成功案例分享 返回数据解析(实时数据,支持高并发请求)
lazada获得lazada商品详情 API接口调用成功案例分享 返回数据解析(实时数据,支持高并发请求)
|
6月前
|
API
各大电商平台API接口调用展示
各大电商平台API接口调用展示
|
7月前
|
文字识别 监控 Java
一文看懂车牌识别OCR:从技术原理到 API Java 示例代码接入
一文看懂车牌识别OCR:从技术原理到 API Java 示例代码接入
168 0
一文看懂车牌识别OCR:从技术原理到 API Java 示例代码接入
|
7月前
|
人工智能 自然语言处理 测试技术
GPT-4 API 接口调用及价格分析
对开发者来说,GPT-4最激动人心的是API接口同步发布。我今天获得了API访问权限,本文将跟大家分享GPT-4 API接口的使用以及大家关心的价格分析。
6456 0
GPT-4 API 接口调用及价格分析
|
7月前
|
机器学习/深度学习 文字识别 算法
一文看懂增值税发票识别OCR:从技术原理到 API Java 示例代码接入
一文看懂增值税发票识别OCR:从技术原理到 API Java 示例代码接入
408 0
一文看懂增值税发票识别OCR:从技术原理到 API Java 示例代码接入
|
7月前
|
JavaScript Java 程序员
【chatgpt】openai api 接口调用(go语言版)
【chatgpt】openai api 接口调用(go语言版)
612 0
相关产品
云迁移中心
推荐文章
更多