如何解析"嵌套JSON"并设置为POJO类

时间:2017-10-28 16:00:25

标签: json parsing jackson nested pojo

杰克逊,如何解析"嵌套JSON"并设置为POJO类

Sales.json

{
    "data": {
       "modified_by": "mat",
       "name": "mak",
        "net_total": 0,
        "items": [
            {
                "owner": "shoaib shaikh",
                "modified_by": "mat",
                "doctype": "Item"
             }
        ],
        "owner": "shoaib shaikh",
        "apply_discount_on": "tesla" 
        }
}

1 个答案:

答案 0 :(得分:0)

然后描述您的销售课程 import com.fasterxml.jackson.databind.ObjectMapper; ... ObjectMapper mapper = new ObjectMapper(); Sales staff = mapper.readValue(new File("D:\\staff.json"), Sales.class);

一些帮助链接:https://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/