fastjsonはマップオブジェクトと文字列を変換します

あなたが学んだことを適用し、再版へようこそ、詳細については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