解析的json数据
{
"status":0,
"data":{
"detail":{
"index":"1.23",
"last_index":"1.24",
"week_rate":-0.008,
"max_congest_day":"20190504",
"max_week_day":"6",
"max_index":"1.52"
},
"updatetime":"201905100905"
},
"message":null
}
这里的 status与message很多地方要用,所以写一个基类泛型
@Data
public class ResultTraffic<T>{
/** 状态 0表示正常 其他错误 .*/
private int status;
/** 错误消息 .*/
private String message;
private T data;
}
data字段泛型所指的类
@Data
public class ResultTrafficJamIndex {
/** 状态 0表示正常 其他错误 .*/
private ResultTrafficJamIndexDetails detail;
private String updatetime;
}
@Data
public class ResultTrafficJamIndexDetails {
private String index;
private String last_index;
private double week_rate;
private String max_congest_day;
private String max_week_day;
private String max_index;
}
json 解析为对象
ResultTraffic<ResultTrafficJamIndex> resultTraffic = JSON.parseObject(resultJson,new TypeReference<ResultTraffic<ResultTrafficJamIndex>>(){});
Console.log("======"+resultTraffic.getData().getDetail().getWeek_rate());