public static void main(String[] args) {
List<Student> list=new ArrayList<>();
Student student=new Student("bob",24);
Student student12=new Student("lily", 23);
list.add(student);
list.add(student12);
System.out.println("*******JSON.toJSONString(student)*******");
String str1=JSON.toJSONString(student);
System.out.println(str1);
System.out.println(JSON.toJSONString(list));
System.out.println();
System.out.println("******JSON.parseObject(str1,Student.class)*******");
//Student stu1=JSON.parseObject(str1,new TypeReference<Student>(){});
Student stu1=JSON.parseObject(str1,Student.class);
System.out.println(stu1);
System.out.println();
System.out.println("******j(JSONObject)JSON.toJSON(student)t******");
JSONObject jsonObject1=(JSONObject)JSON.toJSON(student);
System.out.println(jsonObject1.getString("name"));
System.out.println();
System.out.println("******JSON.toJavaObject(jsonObject1, Student.class)*****");
Student student2=JSON.toJavaObject(jsonObject1, Student.class);
System.out.println(student2);
System.out.println();
System.out.println("*******(JSONArray)JSON.toJSON(stulist)******");
List<Student> stulist=new ArrayList<>();
for(int i=0;i<5;i++){
stulist.add(new Student("student"+i, i));
}
JSONArray jsonArrays=(JSONArray)JSON.toJSON(stulist);
for(int i=0;i<jsonArrays.size();i++){
System.out.println(jsonArrays.getJSONObject(i));
}
System.out.println();
System.out.println("*****jjsonArrays.getJSONObject(i), Student.class*****");
List<Student> myList=new ArrayList<>();
for(int i=0;i<jsonArrays.size();i++){
Student student3=JSON.toJavaObject(jsonArrays.getJSONObject(i), Student.class);
myList.add(student3);
}
for(Student stu:myList){
System.out.println(stu);
}
System.out.println();
System.out.println("*****JSON.toJSONString(jsonObject1);*****");
String str4=JSON.toJSONString(jsonObject1);
System.out.println(str4);
System.out.println();
System.out.println("*******JSON.parseObject(str1);*****");
JSONObject jso1=JSON.parseObject(str1);
System.out.println(jso1.getString("name"));
System.out.println();
System.out.println("*****JSON.parseArray(JSON.toJSONString(stulist)*****");
JSONArray jArray=JSON.parseArray(JSON.toJSONString(stulist));
for(int i=0;i<jArray.size();i++){
System.out.println(jArray.getJSONObject(i));
}
System.out.println();
}
复制
文章转载自元素周期表A,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年4月中国数据库流行度排行榜:OB高分复登顶,崖山稳驭撼十强
墨天轮编辑部
1981次阅读
2025-04-09 15:33:27
2025年3月国产数据库大事记
墨天轮编辑部
897次阅读
2025-04-03 15:21:16
2025年3月国产数据库中标情况一览:TDSQL大单622万、GaussDB大单581万……
通讯员
616次阅读
2025-04-10 15:35:48
数据库国产化替代深化:DBA的机遇与挑战
代晓磊
593次阅读
2025-04-27 16:53:22
征文大赛 |「码」上数据库—— KWDB 2025 创作者计划启动
KaiwuDB
509次阅读
2025-04-01 20:42:12
数据库,没有关税却有壁垒
多明戈教你玩狼人杀
497次阅读
2025-04-11 09:38:42
国产数据库需要扩大场景覆盖面才能在竞争中更有优势
白鳝的洞穴
477次阅读
2025-04-14 09:40:20
最近我为什么不写评论国产数据库的文章了
白鳝的洞穴
424次阅读
2025-04-07 09:44:54
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
378次阅读
2025-04-17 17:02:24
天津市政府数据库框采结果公布,7家数据库产品入选!
通讯员
368次阅读
2025-04-10 12:32:35