JSONObject String, converted entity class

JSONObject and String, converting each entity class

// class object is converted into an entity of type String JSON string
JSONObject.toJSONString (Entity class object) == String


// String type JSON string into the entity class object
JSONObject.toJavaObject (JSON string, the entity class object) == entity


// Json string into a target JSONObject
JSONObject.parseObject (JSON string) == JSONObject


// JSON string into a target entity class
JSONObject.parseObject (JSON string, the entity class object) == entity


eg:

User u = new User();
String jsonStr = JSONObject.toJSONString(u);
 
String jsonStr = "{\"userName\":\"admin\"}";
Refund r = JSONObject.toJavaObject(jsonStr,User.class);
 
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
 
User u = JSONObject.parseObject(jsonStr,User.class);

 

Guess you like

Origin www.cnblogs.com/xguai/p/11822770.html