-2

how can i access i4x-IITB-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1 key and data inside this key ? I have never seen an example json reader that describes how the reader works when the key attribute is a variable such as below example.

{
    "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
            }
        }

2 Answers 2

1

You can deserialize these as a Map with String keys and values defined by a class that you have written a JSON reader for. Play JSON includes a built-in reader for Map types.

Sign up to request clarification or add additional context in comments.

Comments

-1

You may use an iterator. Don't know the exact structure of your json and how flexible it is, but you get the idea with this Java code.

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

1 Comment

Apparently I did not give you the answer you wanted since the down vote. If you can explain a bit more about what you need I can try to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.