fastjson将Map对象和字符串进行转换

学以致用,欢迎转载,更多联系QQ:289325414

转载:https://blog.csdn.net/xlecho/article/details/81131561

将对象转换成为字符串

HashMap<String,Object> map=new HashMap<>(2);
map.put("studentNo","123");
map.put("subjectNo","321");
String strInfo = JSON.toJSONString(map);

将字符串转换成为对象

JSONObject map = JSON.parseObject(strInfoDo);

String studentNo=(String)map.get("studentNo")
String subjectNo=(String)map.get("subjectNo")

将对象集合转换成为字符串

String xmlStr= JSON.toJSONString(list);

--下面的方法比上面会快。快更多,非常多
(hutool.json)
JSONArray jsonArray=new JSONArray(list);
String xmlStr=jsonArray.toString();

将字符串转换成为对象集合

List<User> userList = JSON.parseArray(userStr, User.class);  



 

猜你喜欢

转载自blog.csdn.net/qq_37203082/article/details/100536286