【发布时间】:2014-10-20 00:04:31
【问题描述】:
下面的代码有两个错误...一个在倒数第三行,一个在最后一行。这些行如下,并且都包含以下错误消息“方法 put(JSONObject) 未定义 JSONArray 类型。”这是什么意思,如何解决?
studentJSONArray.put( studentJSONObject );//这是倒数第三行
courseJSONArray.put( courseJSONObject );//这是最后一行
JSONArray courseJSONArray = new JSONArray();
for(int c = 0; c < 40; c++) {
JSONObject courseJSONObject = new JSONObject();
courseJSONObject.put("course name", course.getName());
courseJSONObject.put("course teacher", course.getTeacher());
JSONArray studentJSONArray = new JSONArray();
for(int s = 0; s < 50; s++) {
JSONObject studentJSONObject = new JSONObject();
studentJSONObject.put("student name", course.student.getName());
studentJSONObject.put("student id", course.student.getid());
studentJSONObject.put("student final grade", course.student.getfinalgrade());
JSONArray assignmentJSONArray = new JSONArray();
for(int a = 0; a < 100; a++) {
JSONObject assignmentJSONObject = new JSONObject();
assignmentJSONObject.put("assignment name", getAssignmentName());
assignmentJSONObject.put("category", getAssignmentCategory());
assignmentJSONObject.put("date", getAssignmentDate());
assignmentJSONObject.put("grade", course.student.getAssignmentGrade());
assignmentJSONArray.put( assignmentJSONObject );
}
studentJSONObject.put( "assignments", assignmentJSONArray );
studentJSONArray.put( studentJSONObject );
}
courseJSONObject.put( "students", studentJSONArray );
courseJSONArray.put( courseJSONObject );
}
【问题讨论】:
标签: json arrays jsonobject