我想处理一个来自另一个对象的数组列表,但我希望它仅创建一个新的JSON数组,其中包含学生编号(该编号应与lStudentZelf相同)和aanwezigheid。
{
"klas": "V1A",
"docent": "Buddha",
"les": "AUI",
"studenten": [{
"studentnummer": 12312591,
"status": "afwezig"
},
{
"studentnummer": 1214531,
"status": "aanwezig"
},
{
"studentnummer": 1214531,
"status": "aanwezig"
}
]
}
(这是数组列表的样子,我希望它仅输出studentnumber 1214531的结果,并跟踪该studentnumber有多少个状态为anwezig。)
我尝试了下面的代码,并尝试了其他几种方法,但无济于事。
private void ophalen(Conversation conversation) {
JsonObject lJsonObjectIn = (JsonObject) conversation.getRequestBodyAsJSON();
String lGebruikersnaam = lJsonObjectIn.getString("username");
Student lStudentZelf = informatieSysteem.getStudent(lGebruikersnaam);
int lNummerZelf = lStudentZelf.getStudentNummer(); //lNummerZelf will be the number that needs to be the same as the 'studentennummer' in the list.
ArrayList<Statistiek> Test2 = Statistiek.getStatistieken();
JsonArrayBuilder lJsonArrayBuilder = Json.createArrayBuilder();
for (Statistiek s : Test2) {
JsonObjectBuilder lJsonObjectBuilder= Json.createObjectBuilder();
lJsonObjectBuilder.add("aanwezig", aanwezig);
lJsonObjectBuilder.add("afwezig", afwezig);
lJsonObjectBuilder.add("geoorloofd", gafwezig);
lJsonObjectBuilder.add("vak", vak);
lJsonArrayBuilder.add(lJsonObjectBuilder);
}
String lJsonOutStr = lJsonArrayBuilder.build().toString();
conversation.sendJSONMessage(lJsonOutStr);
}
}
最后,我希望它仅读取studentnummer和状态部分,并跟踪出现一次属于所选studentnummer的特定状态(例如ananzizig 2x for studentnummer 1214531)的次数。