User user = new User("张三", "男", 18);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(user);
JAVA对象 -> JSON字符串
User user = new User("张三", "男", 18);
String userStr = JSONObject.toJSONString(user);
JSON对象 -> JSON字符串
User user = new User("张三", "男", 18);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(user);
String jsonString = jsonObject.toJSONString();
JSON对象 -> Java对象
User user1 = new User("张三", "男", 18);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(user1);
User user = JSONObject.toJavaObject(jsonObject, User.class);
JSON字符串 -> JAVA对象
String userStr = "{\"age\":18,\"name\":\"张三\",\"sex\":\"男\"}";
User user = JSONObject.parseObject(userStr, User.class);