//Java对象转 JSON 字符串
people p1 = new people();
p1.setName("小A");
p1.setAge(19);
String describe = JSON.toJSONString(p1);
p1.setDescribe(describe);
System.out.println(p1);
System.out.println("---------------------");
//JSON 字符串转JSON 对象
String Str = p1.getDescribe();
people copyP1 = JSON.parseObject(Str,people.class);
System.out.println(copyP1);
//JSON日期格式化
Date date = new Date();
System.out.println(JSON.toJSONStringWithDateFormat(date,"yyyy-MM-dd HH:mm:ss.SSS"));
使用JSON实现Java对象和字符串的转换
最新推荐文章于 2024-07-24 02:12:07 发布