资讯专栏INFORMATION COLUMN

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

mengera88 / 1046人阅读

摘要:分享篮球即时比分接口调用的示例代码,可查看在线调用文档,需注册下即时变化的比分数据获取返回内容这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容返回数据如下部分

分享篮球即时比分api接口调用的示例代码,可查看在线调用文档,需注册下https://www.feijing88.com/bas...

</>复制代码

  1. package com.huaying.demo.basketball;
  2. import javax.xml.bind.JAXBContext;
  3. import javax.xml.bind.Unmarshaller;
  4. import javax.xml.bind.annotation.XmlElement;
  5. import javax.xml.bind.annotation.XmlRootElement;
  6. import java.io.ByteArrayInputStream;
  7. import java.nio.charset.StandardCharsets;
  8. import java.nio.file.Files;
  9. import java.nio.file.Paths;
  10. import java.util.List;
  11. import java.util.stream.Collectors;
  12. /**
  13. * @API: 2.即时变化的比分数据
  14. * @Website: https://www.feijing88.com
  15. */
  16. public class BasketballChange {
  17. public static void main(String[] args) {
  18. try {
  19. String content = getContent();
  20. JAXBContext jaxbContext = JAXBContext.newInstance(ChangeList.class);
  21. Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
  22. ChangeList list = (ChangeList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
  23. list.getChangeList().forEach(System.out::println);
  24. } catch (Throwable t) {
  25. t.printStackTrace();
  26. }
  27. }
  28. /**
  29. * 获取API返回内容
  30. *

  31. * Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
  32. */
  33. private static String getContent() {
  34. try {
  35. StringBuilder builder = new StringBuilder();
  36. List lines = Files.readAllLines(Paths.get("./src/main/resources/BasketballChange.xml"), StandardCharsets.UTF_8);
  37. lines.forEach(line -> builder.append(line));
  38. return builder.toString();
  39. } catch (Throwable t) {
  40. t.printStackTrace();
  41. return "";
  42. }
  43. }
  44. @XmlRootElement(name = "c")
  45. public static class ChangeList {
  46. @XmlElement(name = "h")
  47. private List itemList;
  48. public List getChangeList() {
  49. return itemList.stream().map(s -> {
  50. Change change = new Change();
  51. change.parse(s);
  52. return change;
  53. }).collect(Collectors.toList());
  54. }
  55. }
  56. public static class Change {
  57. private String matchId;
  58. private int matchStatus;
  59. private String remainTime;
  60. private int homeScore;
  61. private int homeScoreFirst;
  62. private int homeScoreSecond;
  63. private int homeScoreThird;
  64. private int homeScoreFourth;
  65. private int homeScoreFirstOT;
  66. private int homeScoreSecondOT;
  67. private int homeScoreThirdOT;
  68. private int awayScore;
  69. private int awayScoreFirst;
  70. private int awayScoreSecond;
  71. private int awayScoreThird;
  72. private int awayScoreFourth;
  73. private int awayScoreFirstOT;
  74. private int awayScoreSecondOT;
  75. private int awayScoreThirdOT;
  76. public void parse(String data) {
  77. String[] values = data.split("^");
  78. matchId = values[0];
  79. matchStatus = parseInt(values[1]);
  80. remainTime = values[2];
  81. homeScore = parseInt(values[3]);
  82. homeScoreFirst = parseInt(values[5]);
  83. homeScoreSecond = parseInt(values[7]);
  84. homeScoreThird = parseInt(values[9]);
  85. homeScoreFourth = parseInt(values[11]);
  86. homeScoreFirstOT = parseInt(values[16]);
  87. homeScoreSecondOT = parseInt(values[18]);
  88. homeScoreThirdOT = parseInt(values[20]);
  89. awayScore = parseInt(values[4]);
  90. awayScoreFirst = parseInt(values[6]);
  91. awayScoreSecond = parseInt(values[8]);
  92. awayScoreThird = parseInt(values[10]);
  93. awayScoreFourth = parseInt(values[12]);
  94. awayScoreFirstOT = parseInt(values[17]);
  95. awayScoreSecondOT = parseInt(values[19]);
  96. awayScoreThirdOT = parseInt(values[21]);
  97. }
  98. private int parseInt(String data) {
  99. return data == null || data.isEmpty() ? 0 : Integer.valueOf(data);
  100. }
  101. @Override
  102. public String toString() {
  103. return "Change{" +
  104. "matchId="" + matchId + """ +
  105. ", matchStatus=" + matchStatus +
  106. ", remainTime="" + remainTime + """ +
  107. ", homeScore=" + homeScore +
  108. ", homeScoreFirst=" + homeScoreFirst +
  109. ", homeScoreSecond=" + homeScoreSecond +
  110. ", homeScoreThird=" + homeScoreThird +
  111. ", homeScoreFourth=" + homeScoreFourth +
  112. ", homeScoreFirstOT=" + homeScoreFirstOT +
  113. ", homeScoreSecondOT=" + homeScoreSecondOT +
  114. ", homeScoreThirdOT=" + homeScoreThirdOT +
  115. ", awayScore=" + awayScore +
  116. ", awayScoreFirst=" + awayScoreFirst +
  117. ", awayScoreSecond=" + awayScoreSecond +
  118. ", awayScoreThird=" + awayScoreThird +
  119. ", awayScoreFourth=" + awayScoreFourth +
  120. ", awayScoreFirstOT=" + awayScoreFirstOT +
  121. ", awayScoreSecondOT=" + awayScoreSecondOT +
  122. ", awayScoreThirdOT=" + awayScoreThirdOT +
  123. "}";
  124. }
  125. }
  126. }

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

</>复制代码

  1. 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}
  2. 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}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/45255.html

相关文章

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

    摘要:分享篮球即时比分接口调用的示例代码,可查看在线调用文档,需注册下即时变化的比分数据获取返回内容这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容返回数据如下部分 分享篮球即时比分api接口调用的示例代码,可查看在线调用文档,需注册下https://www.feijing88.com/bas... package com.huaying.demo.basketball;...

    bigdevil_s 评论0 收藏0
  • 篮球即时比分api接口调用示例代码

    摘要:分享篮球即时比分接口调用的示例代码,可查看在线调用文档,需注册下即时变化的比分数据获取返回内容这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容返回数据如下部分 分享篮球即时比分api接口调用的示例代码,可查看在线调用文档,需注册下https://www.feijing88.com/bas... package com.huaying.demo.basketball;...

    harriszh 评论0 收藏0
  • 如何获取篮球即时赔率api接口

    摘要:篮球数据即时赔率调用示例代码,在线文档可注册下,篮球赔率接口详情页篮球全场赔率接口为了展示只输出条数据,实际不止获取返回内容这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容返回数据如下部分友谊赛泛美男篮菲专员 篮球数据【即时赔率】API调用示例代码,在线文档可注册下,篮球赔率接口详情页 import java.nio.charset.StandardCharsets...

    hightopo 评论0 收藏0
  • 如何获取篮球即时赔率api接口

    摘要:篮球数据即时赔率调用示例代码,在线文档可注册下,篮球赔率接口详情页篮球全场赔率接口为了展示只输出条数据,实际不止获取返回内容这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容返回数据如下部分友谊赛泛美男篮菲专员 篮球数据【即时赔率】API调用示例代码,在线文档可注册下,篮球赔率接口详情页 import java.nio.charset.StandardCharsets...

    asoren 评论0 收藏0

发表评论

0条评论

mengera88

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<