电竞英雄联盟数据API接口 - 【赛事列表】API调用示例代码

野子电竞数据官网改版https://www.xxe.io/全新登场
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**

*/
public class LolLeague {

public static void main(String[] args) {
    try {
        String content = getContent();
        Respond rsp = JSON.parseObject(content, Respond.class);
        System.out.println(rsp.code);
        System.out.println(rsp.message);
        rsp.getLeagueList().forEach(System.out::println);

    } catch (Throwable t) {
        t.printStackTrace();
    }
}

/**
 * 获取API返回内容
 * <p>
 * Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
 */
private static String getContent() {
    try {
        StringBuilder builder = new StringBuilder();
        List<String> lines = Files.readAllLines(Paths.get("./src/main/resources/LolLeague.json"), StandardCharsets.UTF_8);
        lines.forEach(builder::append);
        return builder.toString();
    } catch (Throwable t) {
        t.printStackTrace();
        return "";
    }
}


public static class Respond {
    @JSONField(name = "code")
    private int code;
    @JSONField(name = "message")
    private String message;
    @JSONField(name = "data")
    private List<League> leagueList;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<League> getLeagueList() {
        return leagueList;
    }

    public void setLeagueList(List<League> leagueList) {
        this.leagueList = leagueList;
    }
}

public static class League {
    @JSONField(name = "league_id")
    private int leagueId;
    @JSONField(name = "name")
    private String name;
    @JSONField(name = "name_en")
    private String nameEn;
    @JSONField(name = "short_name")
    private String nameShort;
    @JSONField(name = "start_time")
    private long startTime;
    @JSONField(name = "end_time")
    private long endTime;
    @JSONField(name = "organizer")
    private String organizer;
    @JSONField(name = "logo")
    private String logo;
    @JSONField(name = "address")
    private String address;
    @JSONField(name = "team_ids")
    private List<Integer> teamIds;
    @JSONField(name = "status")
    private int status;

    @Override
    public String toString() {
        return "League{" +
                "leagueId=" + leagueId +
                ", name='" + name + '\'' +
                ", nameEn='" + nameEn + '\'' +
                ", nameShort='" + nameShort + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", organizer='" + organizer + '\'' +
                ", logo='" + logo + '\'' +
                ", address='" + address + '\'' +
                ", teamIds=" + teamIds +
                ", status=" + status +
                '}';
    }

    public void setLeagueId(int leagueId) {
        this.leagueId = leagueId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setNameEn(String nameEn) {
        this.nameEn = nameEn;
    }

    public void setNameShort(String nameShort) {
        this.nameShort = nameShort;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public void setOrganizer(String organizer) {
        this.organizer = organizer;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setTeamIds(List<Integer> teamIds) {
        this.teamIds = teamIds;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}

}

    原文作者:待你幼稚完
    原文地址: https://segmentfault.com/a/1190000020241212
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞