篮球即时比分api接口调用示例代码
来源:SegmentFault
时间:2023-02-25 07:45:01 164浏览 收藏
有志者,事竟成!如果你在学习数据库,那么本文《篮球即时比分api接口调用示例代码》,就很适合你!文章讲解的知识点主要包括MySQL、Java、github、python、javascript,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~
分享篮球即时比分api接口调用的示例代码,可查看在线调用文档,需注册下https://www.feijing88.com/bas...
package com.huaying.demo.basketball; 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返回内容 ** Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容 */ private static String getContent() { try { StringBuilder builder = new StringBuilder(); List
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 itemList; public List 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='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} 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}
今天带大家了解了MySQL、Java、github、python、javascript的相关知识,希望对你有所帮助;关于数据库的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
-
499 收藏
-
244 收藏
-
235 收藏
-
157 收藏
-
101 收藏
-
475 收藏
-
266 收藏
-
273 收藏
-
283 收藏
-
210 收藏
-
371 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 507次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习