共计 4504 个字符,预计需要花费 12 分钟才能阅读完成。
电竞 LOL 数据 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: 赔率信息
* @Website: https://www.feijing88.com
*/
public class LolBet {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.getData().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/LolBet.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
private List<Bet> data;
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<Bet> getData() {return data;}
public void setData(List<Bet> data) {this.data = data;}
}
public static class Bet {
@JSONField
private String betId;
@JSONField
private String matchId;
@JSONField
private String title;
@JSONField
private long endTime;
@JSONField
private int status;
@JSONField
private String resultId;
@JSONField
private List<Options> options;
@JSONField
private int betType;
@JSONField
private int boardNum;
@JSONField
private String typeDesc;
@Override
public String toString() {
return "Bet{" +
"betId='" + betId + '\'' +
", matchId='" + matchId + '\'' +
", title='" + title + '\'' +
", endTime=" + endTime +
", status=" + status +
", resultId='" + resultId + '\'' +
", options=" + options +
", betType=" + betType +
", boardNum=" + boardNum +
", typeDesc='" + typeDesc + '\'' +
'}';
}
public void setBetId(String betId) {this.betId = betId;}
public void setMatchId(String matchId) {this.matchId = matchId;}
public void setTitle(String title) {this.title = title;}
public void setEndTime(long endTime) {this.endTime = endTime;}
public void setStatus(int status) {this.status = status;}
public void setResultId(String resultId) {this.resultId = resultId;}
public void setOptions(List<Options> options) {this.options = options;}
public void setBetType(int betType) {this.betType = betType;}
public void setBoardNum(int boardNum) {this.boardNum = boardNum;}
public void setTypeDesc(String typeDesc) {this.typeDesc = typeDesc;}
}
public static class Options {
@JSONField
private String betItemId;
@JSONField
private String teamId;
@JSONField
private String name;
@JSONField
private String odds;
@Override
public String toString() {
return "Options{" +
"betItemId='" + betItemId + '\'' +
", teamId='" + teamId + '\'' +
", name='" + name + '\'' +
", odds='" + odds + '\'' +
'}';
}
public void setBetItemId(String betItemId) {this.betItemId = betItemId;}
public void setTeamId(String teamId) {this.teamId = teamId;}
public void setName(String name) {this.name = name;}
public void setOdds(String odds) {this.odds = odds;}
}
}
API 返回数据如下(部分):
200
成功
Bet{betId='516641', matchId='2908', title='全场获胜', endTime=0, status=1, resultId='null', options=[Options{betItemId='3536555', teamId='601', name='Origen', odds='2.63'}, Options{betItemId='3536556', teamId='67', name='G2', odds='1.47'}], betType=1, boardNum=0, typeDesc=''}
Bet{betId='60758', matchId='2908', title='全场获胜', endTime=1547848500000, status=1, resultId='null', options=[Options{betItemId='67663', teamId='601', name='Origen', odds='2.47'}, Options{betItemId='67664', teamId='67', name='G2', odds='1.51'}], betType=1, boardNum=0, typeDesc=''}
Bet{betId='518601', matchId='2908', title='1 血', endTime=0, status=1, resultId='null', options=[Options{betItemId='3540209', teamId='601', name='Origen', odds='2.09'}, Options{betItemId='3540210', teamId='67', name='G2', odds='1.72'}], betType=4, boardNum=0, typeDesc=''}
Bet{betId='518602', matchId='2908', title='10 杀', endTime=0, status=1, resultId='null', options=[Options{betItemId='3540211', teamId='601', name='Origen', odds='2.34'}, Options{betItemId='3540212', teamId='67', name='G2', odds='1.58'}], betType=6, boardNum=0, typeDesc=''}
Bet{betId='518660', matchId='2908', title='首塔', endTime=0, status=1, resultId='null', options=[Options{betItemId='3540205', teamId='601', name='Origen', odds='2.15'}, Options{betItemId='3540206', teamId='67', name='G2', odds='1.68'}], betType=7, boardNum=0, typeDesc=''}
Bet{betId='518666', matchId='2908', title='小龙首杀', endTime=0, status=1, resultId='null', options=[Options{betItemId='3540491', teamId='601', name='Origen 首 小龙', odds='2.09'}, Options{betItemId='3540492', teamId='67', name='G2 首 小龙', odds='1.72'}], betType=8, boardNum=0, typeDesc=''}
正文完