分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

JsonObject、JsonArray操作json的个人总结

发布时间:2023-09-06 01:17责任编辑:顾先生关键词:jsjson

介绍 JsonObject、JsonArray之前,先介绍下JsonConfig

JsonConfig:

  1. setClassMap(Map classMap)
    设置json属性类型,上json里的其中值为List时,可通过此属性设置属性类型
    Map jMap = new HashMap();jMap.put("contactPersonList",ContactPerson.class);jMap.put("subscribedList",InvestorSubscribed.class);jsonConfig.setClassMap(jMap);
  2. setRootClass(Class rootClass)
    设置json要转化的java类型
  3. setExcludes(String[] excludes)
    去除不需要转化的属性
  4. setJavaPropertyFilter(PropertyFilter javaPropertyFilter)
    通过实现PropertyFilter 的apply方法来去除不需要转化的属性。当返回true时,则过滤(其中ower为当前实体类,name为属性,value为值)
     jsonConfig.setJavaPropertyFilter((ower,name,value) -> { ???????????return true; ?});

JsonObject常用方法:

  1. Object toBean(JSONObject jsonObject)
  2. Object toBean(JSONObject jsonObject, Class beanClass)
    beabClass既是设置JsonConfigde的RootClass
  3. Object toBean(JSONObject jsonObject, Class beanClass, Map classMap)
  4. Object toBean(JSONObject jsonObject, JsonConfig jsonConfig)

JsonArray常用方法:

  1. Collection toCollection(JSONArray jsonArray)
  2. Collection toCollection(JSONArray jsonArray, Class objectClass)
  3. Collection toCollection(JSONArray jsonArray, JsonConfig jsonConfig)

JsonObject、JsonArray操作json的个人总结

原文地址:http://www.cnblogs.com/wdj-it/p/7660602.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved