您应该构建描述您的响应的数据模型。我看到 2 个类:Response
和Info
. 信息类
class Info {
private String niveau;
private String naam;
private int lln;
private String klas;
public String getNiveau() {
return niveau;
}
public void setNiveau(String niveau) {
this.niveau = niveau;
}
public String getNaam() {
return naam;
}
public void setNaam(String naam) {
this.naam = naam;
}
public int getLln() {
return lln;
}
public void setLln(int lln) {
this.lln = lln;
}
public String getKlas() {
return klas;
}
public void setKlas(String klas) {
this.klas = klas;
}
@Override
public String toString() {
return "Info [niveau=" + niveau + ", naam=" + naam + ", lln=" + lln
+ ", klas=" + klas + "]";
}
}
响应类:
class Response {
private Info info;
private String[][] schedule;
public Info getInfo() {
return info;
}
public void setInfo(Info info) {
this.info = info;
}
public String[][] getSchedule() {
return schedule;
}
public void setSchedule(String[][] schedule) {
this.schedule = schedule;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Response [info=");
builder.append(info).append(", schedule=");
for (String[] array : schedule) {
builder.append(Arrays.toString(array));
}
builder.append("]");
return builder.toString();
}
}
现在,主要方法可能如下所示:
Gson gson = new GsonBuilder().serializeNulls().create();
Response res = gson.fromJson(response, Response.class);
System.out.println(res);
该程序打印:
Response [info=Info [niveau=H5, naam=Sven Boekelder, lln=15518, klas=H5F], schedule=[IN LKH H5.IN1 447 , ZA H5F , EN TOO H5F 424 , SK VEB H5.SK2 411 , BI ROD H5.BI2 427 , NA BMF H5.NA2 425 , LO SCL H5F T56 , LO SCL H5F T56 , -][M VEB H5F 426 , BI ROD H5.BI2 427 , SK VEB H5.SK2 413 , WB WLH H5.WB1 421 , NE VRH H5F 404 , EN TOO H5F 424 , -, -, -][ZB H5F , NE VRH H5F 404 , -, IN LKH H5.IN1 453 , NA BMF H5.NA2 409 , SK VEB H5.SK2 410 , -, WB WLH H5.WB1 422 , -][-, EN TOO H5F 424 , NA BMF H5.NA2 409 , WB WLH H5.WB1 421 , -, BI ROD H5.BI2 427 , -, -, -][NE VRH H5F 404 , -, IN LKH H5.IN1 447 , -, -, -, -, -, -]]