php篮球比赛,篮球比赛动画直播数据api接口示例

分享下篮球比赛动画直播api数据接口代码示例,详细了解请查看接口文档,需注册下

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;

/**

* 21.篮球比赛动画直播数据

*

* @Website: https://www.feijing88.com

*/

public class BasketballAnimationLive {

public static void main(String[] args) {

try {

String content = getContent();

JAXBContext jaxbContext = JAXBContext.newInstance(ResultList.class);

Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

ResultList list = (ResultList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));

list.getResultList().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/BasketballAnimationLive.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 ResultList {

@XmlElement(name = "match")

private List itemList;

public List getResultList() {

return itemList.stream()

.map(AnimationLive::parse)

.collect(Collectors.toList());

}

}

private static class AnimationLive {

@XmlElement(name = "f")

private String data;

private String matchInfo;

private String animationLive;

public AnimationLive parse() {

String[] values = data.split("!");

matchInfo = getData(values, 0);

animationLive = getData(values, 1);

return this;

}

private String getData(String[] values, int index) {

if (index >= 0 && index < values.length) {

return values[index];

} else {

return null;

}

}

@Override

public String toString() {

return "AnimationLive{" +

"matchInfo='" + matchInfo + '\'' +

", animationLive='" + animationLive + '\'' +

'}';

}

}

}

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

AnimationLive{matchInfo='365898^1679^84^/files/team/20190124183405.jpg^/files/team/20190124185630.jpg^4', animationLive='3430861,0,12,-1,,0'}

AnimationLive{matchInfo='365903^1576^1577^/files/team/20190124182112.jpg^/files/team/20190124181344.jpg^4', animationLive='3430982,0,12,-1,,0'}

AnimationLive{matchInfo='365921^83^723^/files/team/20190124175730.jpg^/files/team/20190124184900.jpg^-1', animationLive='3430956,0,12,-1,,0'}

AnimationLive{matchInfo='365902^732^2079^/files/team/20190124182503.jpg^/files/team/20190124184216.jpg^-1', animationLive='3431088,0,12,-1,,0'}

AnimationLive{matchInfo='353406^73^76^/files/team/73.gif^/files/team/20180508172444.png^-1', animationLive='3433286,0,12,-1,,0'}

AnimationLive{matchInfo='353407^69^707^/files/team/20181110020130.jpg^/files/team/707.jpg^4', animationLive='3433268,0,12,-1,,0'}

AnimationLive{matchInfo='353408^66^75^/files/team/20160426141738.jpg^/files/team/75.gif^4', animationLive='3433215,0,12,-1,,0'}

AnimationLive{matchInfo='353409^67^65^/files/team/67.gif^/files/team/20181110022755.jpg^4', animationLive='3433214,0,12,-1,,0'}

AnimationLive{matchInfo='353410^2013^68^/files/team/2013.gif^/files/team/68.gif^4', animationLive='3433091,0,12,-1,,0'}

AnimationLive{matchInfo='353411^71^72^/files/team/71.gif^/files/team/20181110022628.jpg^-1', animationLive='3433226,0,12,-1,,0'}

AnimationLive{matchInfo='365916^2434^85^/files/team/20190124190057.jpg^/files/team/20190124183337.jpg^0', animationLive='null'}

原文链接:https://segmentfault.com/a/1190000020394582

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值