分享使用 飞鲸体育数据 www.feijing88.com 接口调用的示例代码,Dota2的【近期赛事列表】接口。
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: 近期赛事列表
* @Website: https://www.feijing88.com
*/
public class DotaMatch {
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返回内容
*
* Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
*/
private static String getContent() {
try {
StringBuilder builder = new StringBuilder();
List lines = Files.readAllLines(Paths.get("./src/main/resources/DotaMatch.json"), StandardCharsets.UTF_8);
lines.forEach(builder::append);
return builder.toString();
} catch (Throwable t) {
t.printStackTrace();
return "";
}
}
public static class Respond {
@JSONField
private int code;
@JSONField
private String message;
@JSONField(name = "data")
private List matchList;
public void setCode(int code) {
this.code = code;
}
public void setMessage(String message) {
this.message = message;
}
public void setMatchList(List matchList) {
this.matchList = matchList;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
public List getMatchList() {
return matchList;
}
}
public static class Match {
@JSONField
private String matchId;
@JSONField
private String leagueId;
@JSONField
private long matchTime;
@JSONField
private int status;
@JSONField
private int round;
@JSONField
private String roundName;
@JSONField
private String roundNameEn;
@JSONField
private int roundSession;
@JSONField
private String roundType;
@JSONField
private List battleIds;
@JSONField
private long guessId;
@JSONField
private long groupId;
@JSONField
private int bo;
@JSONField
private int teamAScore;
@JSONField
private int teamAId;
@JSONField
private int teamBScore;
@JSONField
private int teamBId;
@Override
public String toString() {
return "Match{" +
"matchId=" + matchId +
", leagueId=" + leagueId +
", matchTime=" + matchTime +
", status=" + status +
", round=" + round +
", roundName='" + roundName + '\'' +
", roundNameEn='" + roundNameEn + '\'' +
", roundSession=" + roundSession +
", roundType='" + roundType + '\'' +
", battleIds=" + battleIds +
", guessId=" + guessId +
", groupId=" + groupId +
", bo=" + bo +
", teamAScore=" + teamAScore +
", teamAId=" + teamAId +
", teamBScore=" + teamBScore +
", teamBId=" + teamBId +
'}';
}
public void setMatchId(String matchId) {
this.matchId = matchId;
}
public void setLeagueId(String leagueId) {
this.leagueId = leagueId;
}
public void setMatchTime(long matchTime) {
this.matchTime = matchTime;
}
public void setStatus(int status) {
this.status = status;
}
public void setRound(int round) {
this.round = round;
}
public void setRoundName(String roundName) {
this.roundName = roundName;
}
public void setRoundNameEn(String roundNameEn) {
this.roundNameEn = roundNameEn;
}
public void setRoundSession(int roundSession) {
this.roundSession = roundSession;
}
public void setRoundType(String roundType) {
this.roundType = roundType;
}
public void setBattleIds(List battleIds) {
this.battleIds = battleIds;
}
public void setGuessId(long guessId) {
this.guessId = guessId;
}
public void setGroupId(long groupId) {
this.groupId = groupId;
}
public void setBo(int bo) {
this.bo = bo;
}
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=lgwil078j7il44l0350m798j57j5685j473l, leagueId=L006341, matchTime=1566270000000, status=0, round=1, roundName='胜者组第一轮(BO3)', roundNameEn='Upper Bracket Round 1 (BO3)', roundSession=1, roundType='win', battleIds=[], guessId=100180639, groupId=6478492, bo=3, teamAScore=0, teamAId=2667, teamBScore=0, teamBId=4941}
Match{matchId=lgwi1mki177k19k0n23m1j2lk8944460jk09, leagueId=L006341, matchTime=1566279000000, status=0, round=1, roundName='胜者组第一轮(BO3)', roundNameEn='Upper Bracket Round 1 (BO3)', roundSession=2, roundType='win', battleIds=[], guessId=100180642, groupId=6478492, bo=3, teamAScore=0, teamAId=2688, teamBScore=0, teamBId=68278}
Match{matchId=lgwiin0n2312n5l2005mk9mij9k9n2nm4380, leagueId=L006341, matchTime=1566286800000, status=0, round=1, roundName='败者组第一轮(BO1)', roundNameEn='Lower Bracket Round 1(BO1)', roundSession=1, roundType='lose', battleIds=[], guessId=100180627, groupId=6478492, bo=1, teamAScore=0, teamAId=4910, teamBScore=0, teamBId=79203}
Match{matchId=lgwi5145ij9kkj4ji82ni752m632778m428j, leagueId=L006341, matchTime=1566293400000, status=0, round=1, roundName='败者组第一轮(BO1)', roundNameEn='Lower Bracket Round 1(BO1)', roundSession=2, roundType='lose', battleIds=[], guessId=100180630, groupId=6478492, bo=1, teamAScore=0, teamAId=4168, teamBScore=0, teamBId=4196}
Match{matchId=lgwin906838196423imiji17l3k224k0492k, leagueId=L006341, matchTime=1566297000000, status=0, round=1, roundName='败者组第一轮(BO1)', roundNameEn='Lower Bracket Round 1(BO1)', roundSession=3, roundType='lose', battleIds=[], guessId=100180633, groupId=6478492, bo=1, teamAScore=0, teamAId=79981, teamBScore=0, teamBId=2665}
Match{matchId=lgwimijl42i6l3lj4m8l1210j97k799570n3, leagueId=L006341, matchTime=1566310200000, status=0, round=1, roundName='败者组第一轮(BO1)', roundNameEn='Lower Bracket Round 1(BO1)', roundSession=4, roundType='lose', battleIds=[], guessId=100180636, groupId=6478492, bo=1, teamAScore=0, teamAId=4132, teamBScore=0, teamBId=4314}
Match{matchId=lgwi996456l2lmnl2173imi61600498k0nm9, leagueId=L006341, matchTime=1566352800000, status=0, round=1, roundName='胜者组第一轮(BO3)', roundNameEn='Upper Bracket Round 1 (BO3)', roundSession=3, roundType='win', battleIds=[], guessId=100180645, groupId=6478492, bo=3, teamAScore=0, teamAId=4929, teamBScore=0, teamBId=79262}
Match{matchId=lgwil713knkil4n03m2509n1ij120kj85mmi, leagueId=L006341, matchTime=1566363600000, status=0, round=1, roundName='胜者组第一轮(BO3)', roundNameEn='Upper Bracket Round 1 (BO3)', roundSession=4, roundType='win', battleIds=[], guessId=100180648, groupId=6478492, bo=3, teamAScore=0, teamAId=4982, teamBScore=0, teamBId=4955}