I am using Jackson to parse some json. An snippet from this json is as follows:
},
"1/1/0": {
"event": "status",
"name": "Alarm Status",
"type": "Alarm",
"location": "Hall"
},
"1/1/1": {
"event": "status",
"name": "Smoke Alarm Status",
"type": "Alarm",
"location": "Hall"
},
I've happily managed to extract the data for each 'object', but I am struggling to obtain the 'name' for each object. In the example above, this would be '1/1/0' and '1/1/1'. I do so in the following way:
final JsonNode node = parser.parseToNode(configJson);
final JsonNode sensorsChild = node.get("sensors");
for (JsonNode root : sensorsChild) {
final String event = root.get("event").asText();
final String name = root.get("name").asText();
final String type = root.get("type").asText();
final String location = root.get("location").asText();
}
I want another line in the the for loop which is something like:
final String id = root.getNodeFieldName();
which would yield '1/1/0' and '1/1/1' respectively. Thanks