fastjson map,String ,json
String 转Json:
String str = "{\"age\":\"24\",\"name\":\"hekliu\"}";
JSONObject jsonObject = JSONObject.parseObject(str);
System.out.println("json对象是:" + jsonObject);
Object object = jsonObject.get("name");
String name= jsonObject.getString("name");
Json 转 String
String str = "{\"age\":\"24\",\"name\":\"hekliu\"}";
JSONObject jsonObject = JSONObject.parseObject(str);
//json对象转字符串
String jsonString = jsonObject.toJSONString();
3.String 转 Map
String str = "{\"age\":\"24\",\"name\":\"hekliu\"}";
JSONObject jsonObject = JSONObject.parseObject(str);
//json对象转Map
Map<String, Object> map = (Map<String, Object>)jsonObject;
System.out.println("map对象是:" + map);
Object object = map.get("age");
4.Map 转String
Map<String,Object> map = new HashMap<>();
map.put("age", 24);
map.put("name", "hekliu");
String jsonString = JSON.toJSONString(map);
5.Map 转 Json
Map<String,Object> map = new HashMap<>();
map.put("age", 24);
map.put("name", "hekliu");
JSONObject json = new JSONObject(map)
6.Json 转 Map
//json对象转Map Map<String, Object> map = (Map<String, Object>)jsonObject;


浙公网安备 33010602011771号