com.alibaba.fastjson.JSONObject use conversion

 

It is often used when com.alibaba.fastjson.JSONObject conversion method, comprising JSON object into a string, the string JSON converted into other java object, using the method summarized below, continuously updated ...

// Java object is converted into String type JSON string 
JSONObject.toJSONString (Java objects) 
 
// String type of Java objects JSON string into 
JSONObject.toJavaObject (JSON string, Java objects. Class ) 
 
// Json string conversion JSONObject objects into 
JSONObject.parseObject (JSON string) 
 
// the JSON string into a Java object 
JSONObject.parseObject (JSON string, Java objects. class )
E.g:
Student r = new Student(); 
String jsonStr
= JSONObject.toJSONString(r);

String jsonStr
= "{\"name\":\"ZhangSan\"}";

Student r = JSONObject.toJavaObject(jsonStr,Refund.class);
JSONObject jsonObject = JSONObject.parseObject(jsonStr); 

Student r = JSONObject.parseObject(jsonStr,Refund.class);

 

Guess you like

Origin www.cnblogs.com/ibigboy/p/11124524.html