//1.java对象转化成String
String s=JSONObject.toJSONString(javaObject.class);
//2. java对象转化成Object
Object str=JSONObject.toJSON(javaObject.class);
//3.String类型转json对象
JSONObject jsonObject= JSONObject.parseObject(str);
//4. String转Object
Object obj=JSONObject.parse(str);
//5. json对象转化成java对象
Student stu=JSONObject.toJavaObject(jsonObject, Student.class);
//6. String转化为Map类型
Map map = JSONObject.parseObject(str,Map.class);
// 7.String类型的集合转List<String>
List<String> list= JSONObject.parseArray(stringList,String.class);
//8. json对象转化为List类型
List list=JSONArray.parseArray(JSONObject.toJSONString(jsonObject, List.class))
//9.String转jsonArray
JSONArray jsaonArray=JSONObject.parseArray(str);
//10.String转java对象
Student stu=JSON.parseObject(str,Student.class);
举例:
1.Json结构的字符串转java对象类型的List
JSONObject jsonObj= JSONObject.parseObject(str);
//如果转化后的json对象包含集合
JSONArray jsonArray= jsonObj.getJSONArray("studentList");
List<Student> deviceInfos = jsonArray.toJavaList(Student.class);
2.obj转List<Map>
List<Map> models = JSONObject.parseArray(JSON.toJSONString(obj), Map.class);