gpt4 book ai didi

java - 用于保存类(class)、学生和作业数据的 JSON

转载 作者:行者123 更新时间:2023-12-01 12:24:42 25 4
gpt4 key购买 nike

我正在尝试使用 JSON 来包含与类(class)/类(class)相关的数据。这个想法是有 40 个类(class)/类(class),每个类(class)/类(class)包含 50 名学生,每个学生有 100 份作业。以下是我到目前为止所想到的。如何修改它以保存上面列出的所有成绩册数据?

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();

}

}

}

最佳答案

JSONArray courses = new JSONArray();
for(int c = 0; i < 40; c++) {
JSONObject course = new JSONObject();
// Add course details
JSONArray students = new JSONArray();
for(int s = 0; s < 50; s++) {
JSONObject student = new JSONObject();
// Add Student details
JSONArray assignments = new JSONArray();
for(int a = 0; a < 100; a++) {
JSONObject assignment = new JSONObject();
// Add assignment details
assignments.put( assignment );
}
student.put( "assignments", assignments );
students.put( student )
}
course.put( "students", students );
courses.put( course );
}

关于java - 用于保存类(class)、学生和作业数据的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26453742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com