-1
我想知道如何在Java-POJO結構中表示這部分JSON文件。 JSON文件本身,我以前從來沒見過的結構:GSON - 處理雙大括號
"codeShares": [
{
"codeShare": {
"airlineCode": "LH",
"trackNumber": "9695",
"suffix": ""
}
},
{
"codeShare": {
"airlineCode": "NH",
"trackNumber": "5350",
"suffix": ""
}
},
{
"codeShare": {
"airlineCode": "TP",
"trackNumber": "8988",
"suffix": ""
}
},
{
"codeShare": {
"airlineCode": "UA",
"trackNumber": "7212",
"suffix": ""
}
}
]
如果每個時間,但一個「正常」的數組有沒有這些「代碼共享」標籤,我想了解如何代表它在一個POJO,但正如我測試,一個列表不起作用。列表大小與文件中「codeShare」標籤的數量相匹配,但實際值(如「airlineCode」等)始終爲空。如果不是列表<>,我需要做什麼?
共享代碼級:
private String airlineCode;
private String trackNumber;
private String suffix;
public CodeShare(String airlineCode, String trackNumber, String suffix) {
this.airlineCode = airlineCode;
this.trackNumber = trackNumber;
this.suffix = suffix;
}
public String getAirlineCode() {
return airlineCode;
}
public String getTrackNumber() {
return trackNumber;
}
public String getSuffix() {
return suffix;
}
@Override
public String toString() {
return airlineCode + trackNumber;
}
Kenta1561
有該工具:看http://www.jsonschema2pojo.org/例如(在右側使用源JSON) – 2017-05-03 15:36:16
謝謝!我發現我必須爲「CodeShare」創建兩個類:D – wafflemiracle