导入import org.json.JSONObject;包 Map<String, Object> map = new HashMap<>();map.put("key1", "value1");map.put("key2", "value2");// 将Map对象转换为JSONObject JSONObject jsonObject = new JSONObject(map);
1.toJson() --转换java对象到json 2.fromJson() --转换json到java对象 例子: 1.toJson() class TestObjectToJson(){ private int data=100; private String str="Hello"; } public static void main(String str[]){ TestObjectToJson obj=new TestObjectToJson(); Gson gson=new Gson(); String jso...
map.put(String.valueOf(key), beanMap.get(key)); } } return map; } /** *将map转换为bean对象 * @param map * @param bean * @return */ public static <T> T changeMapToBean(Map<String, Object> map, T bean) { BeanMap beanMap = BeanMap.create(bean); // 识别对应类型的内容 bean...