(1)将java实体对象与json字符串互转
public class Helloworld {
private void jsonParseObject() throws Exception {
String studentJsons = "{\"name\":\"Lily\", \"age\":\"9\"}";
StudentPo studentPo = JSON.parseObject(studentJsons, StudentPo.class);
System.out.println("解析json字符串成java实体对象其属性age值:" + studentPo.getAge());
String studentConvertJs = JSON.toJSONString(studentPo);
System.out.println("把java实体对象转换成json字符串:" + studentConvertJs);
}
public static void main(String[] args) throws Exception {
// 测试代码
new Helloworld().jsonParseObject();
}
}