I have the following Json structure:
{
"name": "John",
"surname": "Doe",
"languages": [
{"language": "english", "level": "3"},
{"language": "french", "level": "1"}
]
}
I am using the Play Framework to parse Json data from a HTTP message, which was sent by using an self-developed REST service. I know already how I can parse the name and surname from the Json data by looking at the documentation, this is done by:
JsonNode json = request().body().asJson();
String name = json.findPath("name").textValue();
String surname = json.findPath("surname").textValue();
Now my question is, how I can parse the array "languages" in the Json data. I have found some other posts about this problem, but they were all using Scala, which I cant get my head around, so preferably I'm looking for a Java solution.
I have already tried several things, like for example this:
List<JsonNode> languages = json.findPath("languages").getElements();
According to the documentation json.findPath() returns a JsonNode, on which can be called the function getElements(), which would return an Iterator of JsonNode. But I get a compile error on getElements: "The method getElements() is undefined for the type JsonNode"
Anyone knows of an easy way to parse such an array? Thanks in advance