我想使用JSON來包含與課程/課程相關的數據。這個想法是,有40個課程/課程,每個課程/課程包含50名學生,每個學生有100個作業。以下是我迄今爲止所瞭解到的。我如何修改它以保存上面列出的所有成績簿數據?JSON來保存課程,學生和作業數據
public void x(){
JSONObject courseJSONObject = new JSONObject();
JSONArray courseJSONArray = new JSONArray();
JSONObject studentJSONObject = new JSONObject();
JSONArray studentJSONArray = new JSONArray();
JSONObject assignmentJSONObject = new JSONObject();
JSONArray assignmentJSONArray = new JSONArray();
for(int i = 0; i < 40; i++){
courseJSONObject.put("course name", course.getName());
courseJSONObject.put("course teacher", course.getTeacher());
courseJSONArray.put(courseJSONObject);
courseJSONObject = new JSONObject();
for(int j = 0; j < 50; j++){
studentJSONObject.put("student name", course.student.getName());
studentJSONObject.put("student id", course.student.getid());
studentJSONObject.put("student final grade",
course.student.getfinalgrade());
studentJSONArray.put(studentJSONObject);
studentJSONObject = new JSONObject();
for(int k = 0; k < 100; k++){
assignmentJSONObject.put("assignment name", getAssignmentName());
assignmentJSONObject.put("category", getAssignmentCategory());
assignmentJSONObject.put("date", getAssignmentDate());
assignmentJSONObject.put("grade",
course.student.getAssignmentGrade());
assignmentJSONArray.put(assignmentJSONArray);
assignmentJSONObject = new JSONObject();
}
}
}
你想有這樣的[結構](http://pastebin.com/Gif6Y4eB)? – engineercoding 2014-10-19 18:35:58
是的,但是必須有多個課程,每個課程有多個學生,每個學生有多個任務。 – Daron 2014-10-19 18:41:21