我如何访问i4x-IITB-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1密钥和该密钥内的数据?我从未见过一个示例JSON阅读器示例,该示例描述了key属性是变量(例如下面的示例)时阅读器的工作方式。
{
"username": "batista",
"event_type": "problem_check",
"ip": "127.0.0.1",
"event": {
"submission": {
"i4x-IITB-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1": {
"input_type": "choicegroup",
"question": "",
"response_type": "multiplechoiceresponse",
"answer": "MenuInflater.inflate()",
"variant": "",
"correct": true
}
},
"success": "correct",
"grade": 1,
"correct_map": {
"i4x-IITB-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1": {
"hint": "",
"hintmode": null,
"correctness": "correct",
"npoints": null,
"msg": "",
"queuestate": null
}
}
您可以使用迭代器。不知道json的确切结构以及它的灵活性如何,但是您可以通过此Java代码来理解。
JsonNode events = jsonOutput.get("event");
for (Iterator<JsonNode> it = invoices.iterator(); it.hasNext(); ){
// With this line you will get submission, success, grade and correct_map.
JsonNode node = it.next();
// if e.g. submission always has one element it is accessible through node.get(0),
// you may also iterate through e.g. node.elements()
}