我需要json对象输出如下
{ name : primaryLevelPassed, //categoryName of passed student
data : [123,110,106,null,null] },//passed object array
{ name : HighLevelPassed, //categoryName of passed student
data : [223,334,null,null,null] },//passed object array
{ name : primaryLevelFailed, //categoryName of Failed student
data : [null,null,null,23,44] },//failed object array
{ name : HighLevelFailed, //categoryName of Failed student
data : [null,null,06,23,44] }//data JSONArray(failed object array)
我希望在数据JSONArray中显示固定数量的数据点(即max_count = 5),其中应根据大小和值在结尾处开始附加null。
这里我想显示失败和传递的点,所以对于
我正在使用的代码
int max_count = 5;
for(StudentCategory studentCategory : studentAgeCategoryList){
JSONObject subData1 = new JSONObject();
JSONObject subData2 = new JSONObject();
//studentPassed
List<Student> studentPassed = manager.getPassStudent(studentCategory.getCategoryId);
for(Student student : studentPassed){
subData1.put("name", studentCategory.getCategoryName()+"Passed");
JSONArray series1DataPointsArray = new JSONArray();
series1DataPointsArray.add(new JsonPrimitive(student.getTotalMark());
subData1.put("data",series1DataPointsArray);
}
//studentFailed
List<Student> studentFailed = manager.getFailedStudent(studentCategory.getCategoryId);
for(Student student : studentFailed){
subData2.put("name", studentCategory.getCategoryName()+"Failed");
JSONArray series2DataPointsArray = new JSONArray();
series2DataPointsArray.add(new JsonPrimitive(student.getTotalMark());
subData2.put("data",series2DataPointsArray);
}
}
this code gives output
{ name : primaryLevelPassed,
data : [123,110,106,444,223,334,106....] }
{ name : HighLevelFailed,
data : [123,110,106,444,223,334,106....] }
可以请任何人帮助我获得如上所述的输出null。