当前位置: 代码迷 >> Java相关 >> 对象转json的有关问题
  详细解决方案

对象转json的有关问题

热度:52   发布时间:2016-04-22 21:14:40.0
对象转json的问题
我有个对象CustInfo,里面有个属性organ,类型也是个对象。
organ对象中包含一个属性parentOrgan,也是一个对象类型。
 现在我在将CustInfo转json的时候,希望保留organ,
 但是过滤掉organ里面的parentOrgan这个属性,怎么实现啊? 
------解决方案--------------------
只要不影响使用 ,就不用过滤。
------解决方案--------------------
JSONObject CustInfoObj = JSONObject.fromObject(CustInfo);
JSONObject organObj = CustInfoObj.getJSONObject("organ");
organObj.remove("parentOrgan");
这样就去除了organ中的parentOrgan;并且保留了organ