我想解析从服务器接收的json响应。
{"Status":"pass","min":103000.0,"Message":"Operation completed successfully","series":[{"data":[[1507507200000,103000.0],[1510012800000,107874.49150413179],[1512604800000,109453.64095085584],[1515369600000,115992.60554078722],[1517961600000,114557.67384347266],[1520380800000,111781.5205346012],[1523232000000,121114.55974578172],[1525651200000,126418.04557301581],[1528329600000,129649.49324900289],[1531094400000,131222.37238717882],[1533600000000,142142.39441838325],[1536278400000,142411.17969971805],[1538956800000,125147.1845640562],[1544140800000,141337.14434191343],[1546819200000,149062.2616504871],[1549497600000,150398.89724614265],[1551916800000,155610.60356124814]],"name":"Test1","type":"Line"},{"data":[[1507507200000,103000.0],[1510012800000,107800.82650460141],[1512604800000,110050.51234952305],[1515369600000,115843.2777158723],[1517961600000,116428.85968670264],[1520380800000,117524.0658796185],[1523232000000,122098.93610975571],[1525651200000,126490.48580575222],[1528329600000,129015.52592946698],[1531094400000,131998.7382591821],[1533600000000,138066.91286038296],[1536278400000,142287.2302029758],[1538956800000,136210.69656267448],[1544140800000,144444.38168584733],[1546819200000,148289.47241445977],[1549497600000,152253.57425527615],[1551916800000,155341.6134776986]],"name":"Test2","type":"Area"}]}
下面是响应模型
父类(外部Json类)
public class Valuation implements Serializable {
@SerializedName("series")
private List<Series> series = new ArrayList<>();
@SerializedName("min")
private double min;
public double getMin() {
return min;
}
public void setMin(double min) {
this.min = min;
}
public List<Series> getSeries() {
return series;
}
public void setSeries(List<Series> series) {
this.series= series;
}
}
儿童班
系列课程
public class Series implements Serializable {
@SerializedName("data")
private List<HashMap<Long, Double>> seriesData = new ArrayList<HashMap<Long, Double>>();
@SerializedName("name")
private String name;
@SerializedName("type")
private String type;
public List<HashMap<Long, Double>> getSeriesData() {
return seriesData ;
}
public void setSeriesData(List<HashMap<Long, Double>> seriesData ) {
this.seriesData = seriesData ;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
我无法解析此回复。如何获得此响应的解析? 任何帮助表示赞赏。
答案 0 :(得分:0)
您的模型类如下所示。
评估等级
public class Valuation{
private String Status;
private String min;
private String Message;
private ArrayList<Series> series;
public String getStatus (){
return Status;
}
public void setStatus (String Status){
this.Status = Status;
}
public String getMin (){
return min;
}
public void setMin (String min){
this.min = min;
}
public String getMessage (){
return Message;
}
public void setMessage (String Message){
this.Message = Message;
}
public void setSeries(ArrayList<Series> series){
this.series = series;
}
public ArrayList<Series> getSeries(){
return this.series;
}
}
系列课程
public class Series{
private ArrayList<ArrayList<int>> data;
private String name;
private String type;
public void setData(ArrayList<ArrayList<int>> data){
this.data = data;
}
public ArrayList<ArrayList<int>> getData(){
return this.data;
}
public String getName (){
return name;
}
public void setName (String name){
this.name = name;
}
public String getType (){
return type;
}
public void setType (String type){
this.type = type;
}
}
答案 1 :(得分:0)
复制/粘贴您的响应http://www.jsonschema2pojo.org/,然后根据其选择解析类型Jackson或gson将创建模型类。