java 类型之间互相转换

1.String 转 JSONObject

JSONObject resBean = JSONObject.parseObject(json.getString("resourceinfobean"));

2.Object 转 JSONObject

JSONObject json = (JSONObject) JSONObject.toJSON(obj);

3.JSONObject 转 对象

JSONObject resBean = JSONObject.parseObject(json.getString("resourceinfobean"));

ResourceInfoBean bean = JSONUtil.toBean(resBean.toJSONString(), ResourceInfoBean.class);

4.逗号分割String类型转list

String str ="1,2,3";

List<String> split= Arrays.asList(str.split(","));

5.逗号分割String类型转Long类型的list

String str ="1,2,3";

Arrays.stream(str .split(",")).map(Long::valueOf).collect(Collectors.toList());

 

 

 

posted @ 2024-03-04 15:04  JLCUI  阅读(10)  评论(0编辑  收藏  举报