android 循环创建json数组对象,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);
總結
以上是生活随笔為你收集整理的android 循环创建json数组对象,Android-创建JSON数组和JSON对象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 编译小米android系统软件,为And
- 下一篇: 三星note4安装linux,Leano