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

概述

分享使用接口调用的示例代码,篮球数据【篮球文字直播】接口

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @API: 14.篮球文字直播
*/
public class BasketballTextLive {
public static void main(String[] args) {
String content = getContent();
List<TextLive> lives = Arrays.stream(content.split("\$"))
.flatMap((Function<String, Stream<String>>) s -> Arrays.stream(s.split("!")))
.map(TextLive::parseFrom)
.collect(Collectors.toList());
lives.forEach(System.out::println);
}
/**
* 获取API返回内容
*
* Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
*/
private static String getContent() {
try {
StringBuilder builder = new StringBuilder();
List<String> lines = Files.readAllLines(Paths.get("./src/main/resources/BasketballTextLive.xml"), StandardCharsets.UTF_8);
lines.forEach(line -> builder.append(line));
return builder.toString();
} catch (Throwable t) {
t.printStackTrace();
return "";
}
}
public static class TextLive {
private String remainTime;
private String flag;
private int homeScore;
private int awayScore;
private String text;
private String recordId;
private int matchStatus;
private String textNum;
public static TextLive parseFrom(String data) {
TextLive textLive = new TextLive();
textLive.pares(data);
return textLive;
}
private void pares(String data) {
String[] values = data.split("\^");
remainTime = values[0];
flag = values[1];
homeScore = Integer.valueOf(values[2]);
awayScore = Integer.valueOf(values[3]);
text = values[4];
recordId = values[5];
matchStatus = Integer.valueOf(values[6]);
textNum = values[7];
}
@Override
public String toString() {
return "TextLive{" +
"remainTime='" + remainTime + ''' +
", flag='" + flag + ''' +
", homeScore=" + homeScore +
", awayScore=" + awayScore +
", text='" + text + ''' +
", recordId='" + recordId + ''' +
", matchStatus=" + matchStatus +
", textNum='" + textNum + ''' +
'}';
}
}
}

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

TextLive{remainTime='10:00', flag='3', homeScore=0, awayScore=0, text='第1节开始', recordId='7894186', matchStatus=1, textNum='0'}
TextLive{remainTime='09:58', flag='1', homeScore=0, awayScore=0, text='跳球 西尔维亚-福勒斯 vs 伊丽莎白-坎巴琪,丹妮尔-罗宾逊获得球权', recordId='7894187', matchStatus=1, textNum='1'}
TextLive{remainTime='09:40', flag='1', homeScore=0, awayScore=0, text='丹妮尔-罗宾逊失误,被凯尔西-普拉姆抢断', recordId='7894188', matchStatus=1, textNum='2'}
TextLive{remainTime='09:40', flag='1', homeScore=0, awayScore=0, text='丹妮尔-罗宾逊失误丢球,被凯尔西-普拉姆抢断', recordId='7894189', matchStatus=1, textNum='3'}
TextLive{remainTime='09:26', flag='2', homeScore=0, awayScore=0, text='阿贾-威尔逊失误,进攻犯规', recordId='7894190', matchStatus=1, textNum='4'}
TextLive{remainTime='09:14', flag='1', homeScore=0, awayScore=0, text='丹妮尔-罗宾逊3分投篮失败', recordId='7894191', matchStatus=1, textNum='5'}
TextLive{remainTime='09:09', flag='2', homeScore=0, awayScore=0, text='阿贾-威尔逊抢到篮板', recordId='7894192', matchStatus=1, textNum='6'}
TextLive{remainTime='08:50', flag='1', homeScore=0, awayScore=0, text='丹塔斯中距离跳投失败', recordId='7894193', matchStatus=1, textNum='7'}
TextLive{remainTime='08:48', flag='1', homeScore=0, awayScore=0, text='西尔维亚-福勒斯抢到篮板', recordId='7894194', matchStatus=1, textNum='8'}
TextLive{remainTime='08:46', flag='1', homeScore=2, awayScore=0, text='西尔维亚-福勒斯中距离跳投得分', recordId='7894195', matchStatus=1, textNum='9'}
TextLive{remainTime='08:46', flag='1', homeScore=2, awayScore=0, text='西尔维亚-福勒斯反身上篮得分', recordId='7894196', matchStatus=1, textNum='10'}
TextLive{remainTime='08:25', flag='2', homeScore=2, awayScore=1, text='阿贾-威尔逊(2罚)第1罚命中', recordId='7894197', matchStatus=1, textNum='11'}
TextLive{remainTime='08:25', flag='2', homeScore=2, awayScore=2, text='阿贾-威尔逊(2罚)第2罚命中', recordId='7894198', matchStatus=1, textNum='12'}

最后

以上就是淡淡紫菜为你收集整理的篮球数据API接口 - 【篮球文字直播】API调用示例代码的全部内容,希望文章能够帮你解决篮球数据API接口 - 【篮球文字直播】API调用示例代码所遇到的程序开发问题。

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

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

评论列表共有 0 条评论

立即
投稿
返回
顶部