分享使用接口调用的示例代码,篮球数据【篮球文字直播】接口
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76import 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 返回数据如下(部分):
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13TextLive{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接口内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复