700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 电竞英雄联盟数据API接口 - 【近期赛事列表】API调用示例代码

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

时间:2019-02-21 08:08:19

相关推荐

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

分享使用接口调用的示例代码,今天接的是英雄联盟的【近期赛事列表】接口.

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;/*** @API: 近期赛事列表*/public class LolMatch {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.getMatchList().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/LolMatch.json"), StandardCharsets.UTF_8);lines.forEach(builder::append);return builder.toString();} catch (Throwable t) {t.printStackTrace();return "";}}public static class Respond {@JSONFieldprivate int code;@JSONFieldprivate String message;@JSONField(name = "data")private List<Match> matchList;public void setCode(int code) {this.code = code;}public void setMessage(String message) {this.message = message;}public void setMatchList(List<Match> matchList) {this.matchList = matchList;}public int getCode() {return code;}public String getMessage() {return message;}public List<Match> getMatchList() {return matchList;}}public static class Match {@JSONFieldprivate long matchId;@JSONFieldprivate long leagueId;@JSONFieldprivate int status;@JSONFieldprivate long startTime;@JSONFieldprivate String address;@JSONFieldprivate String roundName;@JSONFieldprivate String roundSonName;@JSONFieldprivate int bo;@JSONFieldprivate List<Integer> battleIds;@JSONFieldprivate int teamAScore;@JSONFieldprivate int teamAId;@JSONFieldprivate int teamBScore;@JSONFieldprivate int teamBid;@Overridepublic String toString() {return "Match{" +"matchId=" + matchId +", leagueId=" + leagueId +", status=" + status +", startTime=" + startTime +", address='" + address + '\'' +", roundName='" + roundName + '\'' +", roundSonName='" + roundSonName + '\'' +", bo=" + bo +", battleIds=" + battleIds +", teamAScore=" + teamAScore +", teamAId=" + teamAId +", teamBScore=" + teamBScore +", teamBid=" + teamBid +'}';}public void setMatchId(long matchId) {this.matchId = matchId;}public void setLeagueId(long leagueId) {this.leagueId = leagueId;}public void setStatus(int status) {this.status = status;}public void setStartTime(long startTime) {this.startTime = startTime;}public void setAddress(String address) {this.address = address;}public void setRoundName(String roundName) {this.roundName = roundName;}public void setRoundSonName(String roundSonName) {this.roundSonName = roundSonName;}public void setBo(int bo) {this.bo = bo;}public void setBattleIds(List<Integer> battleIds) {this.battleIds = battleIds;}public void setTeamAScore(int teamAScore) {this.teamAScore = teamAScore;}public void setTeamAId(int teamAId) {this.teamAId = teamAId;}public void setTeamBScore(int teamBScore) {this.teamBScore = teamBScore;}public void setTeamBid(int teamBid) {this.teamBid = teamBid;}}}

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

200成功Match{matchId=3186, leagueId=670, status=0, startTime=1565082000000, address='上海', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=789, teamBScore=0, teamBid=66}Match{matchId=3101, leagueId=670, status=0, startTime=1565089200000, address='北京RNG', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=1, teamBScore=0, teamBid=722}Match{matchId=3102, leagueId=670, status=0, startTime=1565168400000, address='重庆', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=79, teamBScore=0, teamBid=73}Match{matchId=3103, leagueId=670, status=0, startTime=1565175600000, address='杭州', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=74, teamBScore=0, teamBid=63}Match{matchId=3255, leagueId=678, status=0, startTime=1565251200000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=49, teamBScore=0, teamBid=40}Match{matchId=3300, leagueId=678, status=0, startTime=1565262000000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=703, teamBScore=0, teamBid=44}Match{matchId=3306, leagueId=678, status=0, startTime=1565337600000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=46, teamBScore=0, teamBid=704}Match{matchId=3105, leagueId=670, status=0, startTime=1565341200000, address='上海', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=79, teamBScore=0, teamBid=6}Match{matchId=3104, leagueId=670, status=0, startTime=1565348400000, address='西安', roundName='常规赛', roundSonName='第十周', bo=3, battleIds=[], teamAScore=0, teamAId=70, teamBScore=0, teamBid=789}Match{matchId=3307, leagueId=678, status=0, startTime=1565348400000, address='', roundName='常规赛', roundSonName='第九周', bo=3, battleIds=[], teamAScore=0, teamAId=4, teamBScore=0, teamBid=708}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。