背景
在开发过程中,经常需要用到这些互转,因此在网上找了些代码,这里总结一下,方便以后查看。
代码
1、//将map转换成jsonObject
JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(itemMap));
将Map类型的itemInfo转换成json,再经JSONObject转换实现。
2、//将jsonObj转换成Map
Map itemMap = JSONObject.toJavaObject(itemJSONObj, Map.class);
//JOSN.parseObjet()方法同样可以转换
3、//将List转换成JSONArray
JSONArray ja = JSONArray.parseArray(JSON.toJSONString(itemList));
4、json转成对象
List channelItemList = JSON.parseArray(itemJson,ChannelItem.class);
5、将String转换成ArrayList 对象
ArrayList paperAddOrDeleteQuestionList = JSON.parseObject(intelligentAddQuestionListStr,new TypeReference() {});
参考资料
1、https://blog.csdn.net/jianxia801/article/details/82773311
|