Java String ,Map ,Json 相互转化

// json
JSON.toJSONString(json,SerializerFeature.WriteMapNullValue);
String jsonString = JSON.toJSONString(user);  
Map json=JSON.parseObject(jsonString);

JSONObject jsonparm=new JSONObject(map);
String json=jsonparm.toString();

//前提是String的格式是map或json类型的

//String 转Json

 JSONObject  jasonObject = JSONObject.fromObject(str);

//String 转Map

JSONObject  jasonObject = JSONObject.fromObject(str);
Map map = (Map)jasonObject;




//map 转json
Map<String, Object> map = new HashMap<String, Object>();
JSONObject jsonparm=new JSONObject(map);// 可以是map  或者实体类对象
String json=jsonparm.toString();

//string 直接转json
String json=contListRequest.getBindCont().toString();
JSONObject parseObject = JSON.parseObject(json);

//string 转json
String jsonStr = JSON.toJSONString(result);  
Map mapresult=JSON.parseObject(jsonStr);

JSONObject parseObject = JSON.parseObject(result);


/*JSONObject jsonObject = JSONObject.parseObject(json);
            String data = jsonObject.get("item").toString();
            ComUser comuser= JSON.parseObject(data,ComUser.class);
            UseUser user  = JSON.parseObject(data, UseUser.class);
            user.setComUser(comuser);
            String jsondata=JsonMapper.toDateJSON(user);*/
            //UseUser user  = JSON.parseObject(parseObject.toJSONString(), UseUser.class);
原文地址:https://www.cnblogs.com/xkoko/p/9377921.html