【问题标题】:How to Parse " Nested JSON " and set to POJO class如何解析“嵌套 JSON”并设置为 POJO 类
【发布时间】:2018-04-10 00:59:51
【问题描述】:

Jackson,如何解析“嵌套 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" 
        }
}

【问题讨论】:

    标签: json parsing jackson nested pojo


    【解决方案1】:

    描述你的销售类然后做 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/

    【讨论】:

    • new File("D:\\staff.json") 可以是字符串
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 2021-08-20
    相关资源
    最近更新 更多