I found some code for my question but that dose not work in my case
I have a JSON say
{
"A":{
"B":{
"STATUS":"ok",
"TYPE":"Unknown",
"NAME":"UnchangedECN"
}
}
}
How do I fetch the value of Status Type and Name?
Here is what I've tried
long A ;
String STATUS = "";
String TYPE = "";
String NAME = "";
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(new File("BOM.json"));
// Get id
A = root.path("A").asLong();
System.out.println("A : " + A);
// Get Name
JsonNode nameNode = root.path("A");
if (nameNode.isMissingNode()) {
// if "name" node is missing
} else {
STATUS = nameNode.path("STATUS").asText();
// missing node, just return empty string
TYPE = nameNode.path("TYPE").asText();
NAME = nameNode.path("NAME").asText();
System.out.println("STATUS : " + STATUS);
System.out.println("TYPE : " + TYPE);
System.out.println("NAME : " + NAME);
}