使用以下代码:
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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)