So, I get some JSON values from the server but I don\'t know if there will be a particular field or not.
So like:
{ \"regatta_name\":\"ProbaRegatta\"
Json has a method called containsKey()
.
You can use it to check if a certain key is contained in the Json set.
File jsonInputFile = new File("jsonFile.json");
InputStream is = new FileInputStream(jsonInputFile);
JsonReader reader = Json.createReader(is);
JsonObject frameObj = reader.readObject();
reader.close();
if frameObj.containsKey("person") {
//Do stuff
}