1
我想解析一個嵌套的json,其中父鍵包含兩個不同的嵌套鍵對象(不是可以在列表中抽象和序列化的單個模型)。嵌套json的模型類
對於這個例子Json,什麼是正確的Java模型(相應的類)?
{
"name" : "Jack",
"surname" : "Hopper",
"address" : "711-2880 Nulla St. Mankato Mississippi 96522",
"FatherKey" :
{
"ChildKeyNo1" :
{
"defaultKey" : "2_s_g",
"key1" : "4_s_g",
"key2" : "2_s_g"
},
"ChildKeyNo2" :
{
"defaultKey" : "4_s_g",
"key1" : "6_s_g",
"key2" : "7_s_g"
}
}
}
我想出:
public class MainJsonConfiguration{
private String name;
private String surname;
private String address;
private FatherKey fatherKey;
public MainJsonConfiguration(String name, String surname, String address, String fatherKey){
this.name = name;
this.surname = surname;
this.address = address;
this.fatherKey = new FatherKey(new ChildKey(), new ChildKey());
}
}
public class FatherKey{
private ChildKey childKey1;
private ChildKey childKey2;
public FatherKey(ChildKey childKey1, ChildKey childKey2){
this.childKey1 = childKey1;
this.childKey2 = childKey2;
}
}
public class ChildKey{
private String defaultKey;
private String key1;
private String key2;
public ChildKey(){
}
}
,但它的氣味腥....
有什麼建議?
非常感謝您
您可以使用FasterXML Jackson並輕鬆地將其解析爲Map:https://github.com/FasterXML/jackson – duffymo