json转对象,集合,map

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

//json-->bean
User user1 = JSON.parseObject(userJson, User.class);
System.out.println(user1.getUserName());

//json-->List
List<User> list = JSON.parseArray(listJson, User.class);
if(null!=list&&list.size()>0){
  System.out.println(list.get(0).getUserName());
}  

//json-->Map
Map<String, Object> map1 = JSON.parseObject(mapJson, new TypeReference<Map<String, Object>>(){});
System.out.println(map1.get("key1"));
System.out.println(map1.get("key2"));
posted @ 2021-06-29 16:48  !!!嘻哈!!!  阅读(70)  评论(0编辑  收藏  举报