json字符串转map
第一种方法:会忽略null的字段:
Map mapJson = (Map) JSON.parse(arg0);
第二种方法,不会忽视null字段的空串:
Map mapObj = JSONObject.parseObject(str,Map.class);
单元测试:
@Test public void test05(){ String str = "{\"0\":\"zhangsan\",\"1\":\"lisi\",\"2\":\"wangwu\",\"3\":null}"; Map mapObj = JSONObject.parseObject(str,Map.class); LogUtils.info(JSON.toJSONString( mapObj, SerializerFeature.WriteMapNullValue)); }
对象转json字符串保留null字段
方法一:会忽视对象中为null的字段 String strJson = JsonUtil.objectToJson(new person())
方法二,保留对象种为空的字读:
String str = JSON.toJSONString( busOutDetailMQInfo, SerializerFeature.WriteMapNullValue)