Basketball data API interface – [basketball game animation live broadcast change data] API call example code

Time:2020-5-22

For example of API call of basketball game animation live change data, please check the online document for details, and register

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;

/**
 *22. Live broadcast change data of basketball game animation
 *
 * @Website: https://www.feijing88.com
 */
public class BasketballAnimationLiveChange {

    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();
        }
    }

    /**
     *Get API return content
     * <p>
     *Note: in order to facilitate the test, I used a local file, which should be replaced with the real interface to return the content
     */
    private static String getContent() {
        try {
            StringBuilder builder = new StringBuilder();
            List<String> 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<AnimationLive> itemList;

        public List<AnimationLive> 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 return data is as follows (partial):

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'}

Recommended Today

ASP.NET And MSSQL high performance paging instance code

The first is the stored procedure. Only the data I need is retrieved. If the number of pages exceeds the total number of data, the record of the last page will be returned automatically: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO — ============================================= — Author: Clear –Description: high performance paging — http://www.cnblogs.com/roucheng/ — ============================================= Alter […]