Android-创建JSON数组和JSON对象

Android-创建JSON数组和JSON对象,第1张

Android-创建JSON数组和JSON对象

使用以下代码:

JSonObject student1 = new JSonObject();try {    student1.put("id", "3");    student1.put("name", "NAME OF STUDENT");    student1.put("year", "3rd");    student1.put("curriculum", "Arts");    student1.put("birthday", "5/5/1993");} catch (JSonException e) {    // TODO Auto-generated catch block    e.printStackTrace();}JSonObject student2 = new JSonObject();try {    student2.put("id", "2");    student2.put("name", "NAME OF STUDENT2");    student2.put("year", "4rd");    student2.put("curriculum", "scicence");    student2.put("birthday", "5/5/1993");} catch (JSonException e) {    // TODO Auto-generated catch block    e.printStackTrace();}JSonArray jsonArray = new JSonArray();jsonArray.put(student1);jsonArray.put(student2);JSonObject studentsObj = new JSonObject();    studentsObj.put("Students", jsonArray);String jsonStr = studentsObj.toString();    System.out.println("jsonString: "+jsonStr);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5174610.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存