如何解析嵌套JSON“并设置为POJO类 [英] How to Parse " Nested JSON " and set to POJO class
本文介绍了如何解析嵌套JSON“并设置为POJO类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Jackson,如何解析嵌套的JSON"并设置为POJO类
Jackson , How to Parse " Nested JSON " and set to POJO class
Sales.json
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"
}
}
推荐答案
描述您的课程Sales然后执行导入com.fasterxml.jackson.databind.ObjectMapper;...ObjectMapper映射器=新的ObjectMapper();销售人员= mapper.readValue(new File("D:\\ staff.json"),Sales.class);
Describe your class Sales then do
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/
这篇关于如何解析嵌套JSON“并设置为POJO类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文