我尝试解析数据,但是我的问题是我的json响应不是以[]开头。 我使用这个网站(http://www.jsonschema2pojo.org/)来帮助我,但是没有[] ...
不能正常工作我的接口API.java
String BASE_URL = "https://statsapi.web.nhl.com/api/v1/people/";
@Headers("Content-Type: application/json")
@GET("8472382/stats?stats=statsSingleSeason&season=20172018")
Call<Players> getData();
这是我想解析的回复:
{
"stats":[
{
"type":{
"displayName":"statsSingleSeason"
},
"splits":[
{
"season":"20172018",
"stat":{
"timeOnIce":"1711:02",
"assists":10,
"goals":3,
"pim":21,
"shots":93,
"games":81,
"hits":84,
"powerPlayGoals":0,
"powerPlayPoints":0,
"powerPlayTimeOnIce":"06:17",
"evenTimeOnIce":"1442:16",
"penaltyMinutes":"21",
"faceOffPct":0.0,
"shotPct":3.2,
"gameWinningGoals":0,
"overTimeGoals":0,
"shortHandedGoals":0,
"shortHandedPoints":0,
"shortHandedTimeOnIce":"262:29",
"blocked":188,
"plusMinus":-9,
"points":13,
"shifts":2292,
"timeOnIcePerGame":"21:07",
"evenTimeOnIcePerGame":"17:48",
"shortHandedTimeOnIcePerGame":"03:14",
"powerPlayTimeOnIcePerGame":"00:04"
}
}
]
}
]
}
答案 0 :(得分:0)
尝试一下:
String BASE_URL = "https://statsapi.web.nhl.com/api/v1/people/";
@Headers("Content-Type: application/json")
@GET("8472382.json")
Call<Stats> getData();
这些是在stackoverflow上发布的JSON的模型,但是您应该注意Json的URL,因为我尝试了它,它显示了另一个json结构。
在不同的Java文件中创建每个模型,然后添加public
。
class Stats {
private List<Stat> stats;
public List<Stat> getStats() {
return stats;
}
public void setStats(List<Stat> stats) {
this.stats = stats;
}
}
public class Stat {
private StatType type;
private List<Split> splits;
public StatType getType() {
return type;
}
public void setType(StatType type) {
this.type = type;
}
public List<Split> getSplits() {
return splits;
}
public void setSplits(List<Split> splits) {
this.splits = splits;
}
}
class StatType {
private String displayName;
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
}
class Split {
private String season;
StatDetail StatObject;
// Getter Methods
public String getSeason() {
return season;
}
public StatDetail getStat() {
return StatObject;
}
// Setter Methods
public void setSeason(String season) {
this.season = season;
}
public void setStat(StatDetail statObject) {
this.StatObject = statObject;
}
}
class StatDetail {
private String timeOnIce;
private float assists;
private float goals;
private float pim;
private float shots;
private float games;
private float hits;
private float powerPlayGoals;
private float powerPlayPoints;
private String powerPlayTimeOnIce;
private String evenTimeOnIce;
private String penaltyMinutes;
private float faceOffPct;
private float shotPct;
private float gameWinningGoals;
private float overTimeGoals;
private float shortHandedGoals;
private float shortHandedPoints;
private String shortHandedTimeOnIce;
private float blocked;
private float plusMinus;
private float points;
private float shifts;
private String timeOnIcePerGame;
private String evenTimeOnIcePerGame;
private String shortHandedTimeOnIcePerGame;
private String powerPlayTimeOnIcePerGame;
// Getter Methods
public String getTimeOnIce() {
return timeOnIce;
}
public float getAssists() {
return assists;
}
public float getGoals() {
return goals;
}
public float getPim() {
return pim;
}
public float getShots() {
return shots;
}
public float getGames() {
return games;
}
public float getHits() {
return hits;
}
public float getPowerPlayGoals() {
return powerPlayGoals;
}
public float getPowerPlayPoints() {
return powerPlayPoints;
}
public String getPowerPlayTimeOnIce() {
return powerPlayTimeOnIce;
}
public String getEvenTimeOnIce() {
return evenTimeOnIce;
}
public String getPenaltyMinutes() {
return penaltyMinutes;
}
public float getFaceOffPct() {
return faceOffPct;
}
public float getShotPct() {
return shotPct;
}
public float getGameWinningGoals() {
return gameWinningGoals;
}
public float getOverTimeGoals() {
return overTimeGoals;
}
public float getShortHandedGoals() {
return shortHandedGoals;
}
public float getShortHandedPoints() {
return shortHandedPoints;
}
public String getShortHandedTimeOnIce() {
return shortHandedTimeOnIce;
}
public float getBlocked() {
return blocked;
}
public float getPlusMinus() {
return plusMinus;
}
public float getPoints() {
return points;
}
public float getShifts() {
return shifts;
}
public String getTimeOnIcePerGame() {
return timeOnIcePerGame;
}
public String getEvenTimeOnIcePerGame() {
return evenTimeOnIcePerGame;
}
public String getShortHandedTimeOnIcePerGame() {
return shortHandedTimeOnIcePerGame;
}
public String getPowerPlayTimeOnIcePerGame() {
return powerPlayTimeOnIcePerGame;
}
// Setter Methods
public void setTimeOnIce(String timeOnIce) {
this.timeOnIce = timeOnIce;
}
public void setAssists(float assists) {
this.assists = assists;
}
public void setGoals(float goals) {
this.goals = goals;
}
public void setPim(float pim) {
this.pim = pim;
}
public void setShots(float shots) {
this.shots = shots;
}
public void setGames(float games) {
this.games = games;
}
public void setHits(float hits) {
this.hits = hits;
}
public void setPowerPlayGoals(float powerPlayGoals) {
this.powerPlayGoals = powerPlayGoals;
}
public void setPowerPlayPoints(float powerPlayPoints) {
this.powerPlayPoints = powerPlayPoints;
}
public void setPowerPlayTimeOnIce(String powerPlayTimeOnIce) {
this.powerPlayTimeOnIce = powerPlayTimeOnIce;
}
public void setEvenTimeOnIce(String evenTimeOnIce) {
this.evenTimeOnIce = evenTimeOnIce;
}
public void setPenaltyMinutes(String penaltyMinutes) {
this.penaltyMinutes = penaltyMinutes;
}
public void setFaceOffPct(float faceOffPct) {
this.faceOffPct = faceOffPct;
}
public void setShotPct(float shotPct) {
this.shotPct = shotPct;
}
public void setGameWinningGoals(float gameWinningGoals) {
this.gameWinningGoals = gameWinningGoals;
}
public void setOverTimeGoals(float overTimeGoals) {
this.overTimeGoals = overTimeGoals;
}
public void setShortHandedGoals(float shortHandedGoals) {
this.shortHandedGoals = shortHandedGoals;
}
public void setShortHandedPoints(float shortHandedPoints) {
this.shortHandedPoints = shortHandedPoints;
}
public void setShortHandedTimeOnIce(String shortHandedTimeOnIce) {
this.shortHandedTimeOnIce = shortHandedTimeOnIce;
}
public void setBlocked(float blocked) {
this.blocked = blocked;
}
public void setPlusMinus(float plusMinus) {
this.plusMinus = plusMinus;
}
public void setPoints(float points) {
this.points = points;
}
public void setShifts(float shifts) {
this.shifts = shifts;
}
public void setTimeOnIcePerGame(String timeOnIcePerGame) {
this.timeOnIcePerGame = timeOnIcePerGame;
}
public void setEvenTimeOnIcePerGame(String evenTimeOnIcePerGame) {
this.evenTimeOnIcePerGame = evenTimeOnIcePerGame;
}
public void setShortHandedTimeOnIcePerGame(String shortHandedTimeOnIcePerGame) {
this.shortHandedTimeOnIcePerGame = shortHandedTimeOnIcePerGame;
}
public void setPowerPlayTimeOnIcePerGame(String powerPlayTimeOnIcePerGame) {
this.powerPlayTimeOnIcePerGame = powerPlayTimeOnIcePerGame;
}
}