fastJson javaBean objects and JSON conversion

The effect is to fastjson java object into a string, the string into java object, and to facilitate the subsequent logic.

java object are interchangeable and json JSON object operated by:

JavaBean bean = JSON.toJSONString(javaBean);
String str = JSON.pase(str, JaveBean);

JSONObject map can be used as treatment, or can be map-based entity; initializing

初始化方式1:
JSONObject json= new JSONObject();
json.put("1","1");
json.put("1","1");
json.put("1","1");

方式2:
Map<String, Object> map = new HashMap<>();        
map.put("name", "1");
map.put("age", 12);
map.put("birthday", "1999-20-03");
JSONObject json = new JSONObject(zhangsan);
 
方式3:
User user=new User();
user.put("name", "2");
user.put("age", 11);
user.put("birthday", "1999-20-03");
JSONObject json = new JSONObject(zhangsan);

JSONArray

获取JSONObject
JSONObject json = (JSONObject)jsonArray.get(i);
JSONObject json = jsonArray.getJSONObject(i);

 

What's more ?

That's all !

Guess you like

Origin www.cnblogs.com/lalalazar/p/12039728.html