POJO用于​​复杂的JSON

时间:2014-08-28 10:33:23

标签: java json

对于以下JSON,

{
        "Type" : {                          
                            "attribute1" : "value1",
                            "attribute2" : "value2",
                            "attribute3" : "value3",
                            "recordList": {
                                        "record1": [
                                                      {"field": "value"},                                                     
                                                      {"field": "value", "field": "value","field" :{"subrecord1": [{"subfield1": "subvalue1", "subfield2": "subvalue2"}]}},
                                                      {"field": "value", "field": "value","field" :{"subrecord1": [{"subfield1": "subvalue1", "subfield2":[{"subsubfield1": "subsubvalue1", "subsubfield2": "subsubvalue2"}] }]}},
                                                      {"field": {"subrecord1": [{"subfield1": "subvalue1", "subfield2": "subvalue2"}]}, "field": "value","field" :{"subrecord1": [{"subfield1": "subvalue1", "subfield2":[{"subsubfield1": "subsubvalue1", "subsubfield2": "subsubvalue2"}] }]}} 

                                                    ]

                                          },                    
                            "attribute1" : "2014-08-21 03:05:03"
                    }       

}

如何构造POJO以便将其转换为java对象。

1 个答案:

答案 0 :(得分:0)

一种方法是:

    public class Rootobject
    {
        public Type Type { get; set; }
    }

    public class Type
    {
        public String attribute1 { get; set; }
        public String attribute2 { get; set; }
        public String attribute3 { get; set; }
        public Recordlist recordList { get; set; }
    }

    public class Recordlist
    {
        public Record1[] record1 { get; set; }
    }

    public class Record1
    {
        public Object field { get; set; }
    }