1、JSON.parseObject(jsonString, Object.class); //将json字符串转成对象

例子:String jsonStr = '{"id":1,"name":"张三","sex":"男"},{"id":2,"name":"李四","sex":"男"},{"id":3,"name":"王五","sex":"女"}';

JSONOBJECT jsonObject = JSON.pareObject(jsonStr,Oject.class);

结果:{id:1,name:"张三",sex:"男"},{id:2,name:"李四",sex:"男"},{id:3,name:"王五",sex:"女"}'


2、JSON.parse(str);//将字符串转换成对象

例子:String str = '{"id":1,"name":"张三","sex":"男"}';

OBJECT obj = JSON.parse(str);

结果: {"id":1,"name":张三,"sex":男}

特别地注意:大括号里面必须是双引号,否则会抛出异常


3.stringify(obj); //用于从一个对象转换成字符串

例子:Object obj = [id:1,name:"张三"];

String str = stringify(obj);

结果:'{"id":1,"name":张三}'