jackson
pom文件中引入依赖
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
代码
// JSON串转用户对象列表
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
FinancialReview financialReview = objectMapper.readValue(resultJson1.toString(), FinancialReview.class);
fastjson
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
String resultJson1 = "{\"pageSize\":5,\"currentPage\":1,\"totalCount\":3956,\"pageName\":\"page\"," +
"\"pageSizeName\":\"pageSize\",\"data\":[{\"createId\":\"0510048769\"," +
"\"createDate\":1539742868000,\"modifyId\":null,\"modifyDate\":null,\"status\":0," +
"\"destTask\":null,\"lastDestTaskIds\":null,\"lastDestTaskUids\":null,\"actDefId\":null," +
"\"defKey\":null,\"taskId\":null,\"sqlMap\":{},\"authSql\":null," +
"\"busId\":\"d461ec8d-4b63-468d-bb12-50ef555cce35\",\"busBusType\":\"FI-07-01\"," +
"\"busTradeType\":\"400003\",\"busTradeTypeList\":null,\"busRecordNo\":\"20183202CR10035491\"," +
"\"busAccountDate\":1539187200000,\"busAccountDateMin\":null,\"busAccountDateMax\":null," +
"\"busCurrency\":\"CNY\",\"busExchangeRate\":1,\"busAccountType\":null,\"busBusManId\":null," +
"\"busIsWriteOff\":null,\"busOffId\":null,\"busOffRecordNo\":null,\"busAccessoryNum\":null," +
"\"busRemark\":null,\"busStatus\":\"41\",\"busSyncStatus\":\"E\",\"busOrgId\":\"3202100029\"," +
"\"busCompanyId\":\"320210\",\"companyCode\":null,\"busAccountant\":null," +
"\"busAccountantName\":null,\"busAccountYear\":null,\"busAccountMonth\":null," +
"\"busAccountBudat\":null,\"createName\":\"徐忠保\",\"busOrgName\":\"系统集成公司\"," +
"\"busBusManName\":null,\"accountCode\":null,\"busOffStatus\":null,\"busOffSyncStatus\":null," +
"\"busOffAccountCode\":null,\"busAmount\":3000,\"busAmountMin\":null,\"busAmountMax\":null," +
"\"createDateMin\":null,\"createDateMax\":null,\"showReview\":null,\"busNoTaxAmount\":3000," +
"\"busNoTaxAmountMin\":null,\"busNoTaxAmountMax\":null,\"busTaxAmount\":0," +
"\"busTaxAmountMin\":null,\"busTaxAmountMax\":null,\"budatMin\":null,\"budatMax\":null," +
"\"busOrgIdList\":null,\"logId\":\"ae0a0f05-5c97-4599-9c8e-2a585c1a3c2a\",\"busOffLogId\":null}," +
"{\"createId\":\"0510048769\",\"createDate\":1539241073000,\"modifyId\":null,\"modifyDate\":null," +
"\"status\":0,\"destTask\":null,\"lastDestTaskIds\":null,\"lastDestTaskUids\":null," +
"\"actDefId\":null,\"defKey\":null,\"taskId\":null,\"sqlMap\":{},\"authSql\":null," +
"\"busId\":\"8fe1d87b-c876-4c00-b604-caffca9d003e\",\"busBusType\":\"FI-07-01\"," +
"\"busTradeType\":\"400999\",\"busTradeTypeList\":null,\"busRecordNo\":\"20183202CR10035488\"," +
"\"busAccountDate\":1539187200000,\"busAccountDateMin\":null,\"busAccountDateMax\":null," +
"\"busCurrency\":\"CNY\",\"busExchangeRate\":1,\"busAccountType\":null,\"busBusManId\":null," +
"\"busIsWriteOff\":null,\"busOffId\":null,\"busOffRecordNo\":null,\"busAccessoryNum\":null," +
"\"busRemark\":null,\"busStatus\":\"41\",\"busSyncStatus\":\"E\",\"busOrgId\":\"3202100029\"," +
"\"busCompanyId\":\"320210\",\"companyCode\":null,\"busAccountant\":null," +
"\"busAccountantName\":null,\"busAccountYear\":null,\"busAccountMonth\":null," +
"\"busAccountBudat\":null,\"createName\":\"徐忠保\",\"busOrgName\":\"系统集成公司\"," +
"\"busBusManName\":null,\"accountCode\":null,\"busOffStatus\":null,\"busOffSyncStatus\":null," +
"\"busOffAccountCode\":null,\"busAmount\":1170,\"busAmountMin\":null,\"busAmountMax\":null," +
"\"createDateMin\":null,\"createDateMax\":null,\"showReview\":null,\"busNoTaxAmount\":1000," +
"\"busNoTaxAmountMin\":null,\"busNoTaxAmountMax\":null,\"busTaxAmount\":170," +
"\"busTaxAmountMin\":null,\"busTaxAmountMax\":null,\"budatMin\":null,\"budatMax\":null," +
"\"busOrgIdList\":null,\"logId\":\"545bdd9c-cd58-488e-b266-03a793424e29\",\"busOffLogId\":null}," +
"{\"createId\":\"0510048769\",\"createDate\":1539240693000,\"modifyId\":null,\"modifyDate\":null," +
"\"status\":0,\"destTask\":null,\"lastDestTaskIds\":null,\"lastDestTaskUids\":null," +
"\"actDefId\":null,\"defKey\":null,\"taskId\":null,\"sqlMap\":{},\"authSql\":null," +
"\"busId\":\"9a0b887e-6dea-48eb-8c47-b147892832d0\",\"busBusType\":\"FI-07-01\"," +
"\"busTradeType\":\"400003\",\"busTradeTypeList\":null,\"busRecordNo\":\"20183202CR10035487\"," +
"\"busAccountDate\":1539187200000,\"busAccountDateMin\":null,\"busAccountDateMax\":null," +
"\"busCurrency\":\"CNY\",\"busExchangeRate\":1,\"busAccountType\":null,\"busBusManId\":null," +
"\"busIsWriteOff\":null,\"busOffId\":null,\"busOffRecordNo\":null,\"busAccessoryNum\":null," +
"\"busRemark\":null,\"busStatus\":\"41\",\"busSyncStatus\":\"P\",\"busOrgId\":\"3202100029\"," +
"\"busCompanyId\":\"320210\",\"companyCode\":null,\"busAccountant\":null," +
"\"busAccountantName\":null,\"busAccountYear\":null,\"busAccountMonth\":null," +
"\"busAccountBudat\":null,\"createName\":\"徐忠保\",\"busOrgName\":\"系统集成公司\"," +
"\"busBusManName\":null,\"accountCode\":null,\"busOffStatus\":null,\"busOffSyncStatus\":null," +
"\"busOffAccountCode\":null,\"busAmount\":1099.8,\"busAmountMin\":null,\"busAmountMax\":null," +
"\"createDateMin\":null,\"createDateMax\":null,\"showReview\":null,\"busNoTaxAmount\":940," +
"\"busNoTaxAmountMin\":null,\"busNoTaxAmountMax\":null,\"busTaxAmount\":159.8," +
"\"busTaxAmountMin\":null,\"busTaxAmountMax\":null,\"budatMin\":null,\"budatMax\":null," +
"\"busOrgIdList\":null,\"logId\":null,\"busOffLogId\":null},{\"createId\":\"0510047773\"," +
"\"createDate\":1539240537000,\"modifyId\":null,\"modifyDate\":null,\"status\":0," +
"\"destTask\":null,\"lastDestTaskIds\":null,\"lastDestTaskUids\":null,\"actDefId\":null," +
"\"defKey\":null,\"taskId\":null,\"sqlMap\":{},\"authSql\":null," +
"\"busId\":\"48b3ce8d-7de9-46c2-b68c-d2cc76f84e01\",\"busBusType\":\"FI-07-01\"," +
"\"busTradeType\":\"400999\",\"busTradeTypeList\":null,\"busRecordNo\":\"20183202CR10035486\"," +
"\"busAccountDate\":1539187200000,\"busAccountDateMin\":null,\"busAccountDateMax\":null," +
"\"busCurrency\":\"CNY\",\"busExchangeRate\":1,\"busAccountType\":null,\"busBusManId\":null," +
"\"busIsWriteOff\":null,\"busOffId\":null,\"busOffRecordNo\":null,\"busAccessoryNum\":null," +
"\"busRemark\":null,\"busStatus\":\"41\",\"busSyncStatus\":\"P\",\"busOrgId\":\"3202100026\"," +
"\"busCompanyId\":\"320210\",\"companyCode\":null,\"busAccountant\":null," +
"\"busAccountantName\":null,\"busAccountYear\":null,\"busAccountMonth\":null," +
"\"busAccountBudat\":null,\"createName\":\"刘恋\",\"busOrgName\":\"咨询规划研究院\"," +
"\"busBusManName\":null,\"accountCode\":null,\"busOffStatus\":null,\"busOffSyncStatus\":null," +
"\"busOffAccountCode\":null,\"busAmount\":10000,\"busAmountMin\":null,\"busAmountMax\":null," +
"\"createDateMin\":null,\"createDateMax\":null,\"showReview\":null,\"busNoTaxAmount\":10000," +
"\"busNoTaxAmountMin\":null,\"busNoTaxAmountMax\":null,\"busTaxAmount\":0," +
"\"busTaxAmountMin\":null,\"busTaxAmountMax\":null,\"budatMin\":null,\"budatMax\":null," +
"\"busOrgIdList\":null,\"logId\":null,\"busOffLogId\":null},{\"createId\":\"0510047773\"," +
"\"createDate\":1539240189000,\"modifyId\":null,\"modifyDate\":null,\"status\":0," +
"\"destTask\":null,\"lastDestTaskIds\":null,\"lastDestTaskUids\":null,\"actDefId\":null," +
"\"defKey\":null,\"taskId\":null,\"sqlMap\":{},\"authSql\":null," +
"\"busId\":\"b5ca3c80-1916-491b-bf2e-8d2591d91831\",\"busBusType\":\"FI-07-01\"," +
"\"busTradeType\":\"400999\",\"busTradeTypeList\":null,\"busRecordNo\":\"20183202CR10035485\"," +
"\"busAccountDate\":1539187200000,\"busAccountDateMin\":null,\"busAccountDateMax\":null," +
"\"busCurrency\":\"CNY\",\"busExchangeRate\":1,\"busAccountType\":null,\"busBusManId\":null," +
"\"busIsWriteOff\":null,\"busOffId\":null,\"busOffRecordNo\":null,\"busAccessoryNum\":null," +
"\"busRemark\":null,\"busStatus\":\"41\",\"busSyncStatus\":\"P\",\"busOrgId\":\"3202100026\"," +
"\"busCompanyId\":\"320210\",\"companyCode\":null,\"busAccountant\":null," +
"\"busAccountantName\":null,\"busAccountYear\":null,\"busAccountMonth\":null," +
"\"busAccountBudat\":null,\"createName\":\"刘恋\",\"busOrgName\":\"咨询规划研究院\"," +
"\"busBusManName\":null,\"accountCode\":null,\"busOffStatus\":null,\"busOffSyncStatus\":null," +
"\"busOffAccountCode\":null,\"busAmount\":11111,\"busAmountMin\":null,\"busAmountMax\":null," +
"\"createDateMin\":null,\"createDateMax\":null,\"showReview\":null,\"busNoTaxAmount\":11111," +
"\"busNoTaxAmountMin\":null,\"busNoTaxAmountMax\":null,\"busTaxAmount\":0," +
"\"busTaxAmountMin\":null,\"busTaxAmountMax\":null,\"budatMin\":null,\"budatMax\":null," +
"\"busOrgIdList\":null,\"logId\":null,\"busOffLogId\":null}],\"totalPage\":792," +
"\"thisPageFirstElementNumber\":1,\"thisPageLastElementNumber\":5,\"nextPage\":2," +
"\"previousPage\":0,\"linkPageNumbers\":[1,2,3,4,5,6,7,8,9,10],\"pageArr\":[1,2,3,4,5,6]," +
"\"first\":0,\"last\":5}";
FinancialReview financialReview = JSON.parseObject(resultJson1, FinancialReview.class);
注意
json中数组和集合的区别
POJO模型
private List<Data> data ;
private List<Integer> linkPageNumbers ;
private List<Integer> pageArr ;
这三个属性都是List集合,但是集合中的元素可以是对象也可以是Integer基本数据类型
/**
* Created by HASEE on 2018/10/17 9:48
* 财务复核JOPO
*/
public class FinancialReview {
private int pageSize;
private int currentPage;
private int totalCount;
private String pageName;
private String pageSizeName;
private List<Data> data ;
private int totalPage;
private int thisPageFirstElementNumber;
private int thisPageLastElementNumber;
private int nextPage;
private int previousPage;
private List<Integer> linkPageNumbers ;
private List<Integer> pageArr ;
private int first;
private int last;
setter/getter ......
360截图16620610649968.png
网友评论