Keys from Map are printed as [index].keyname. How to get the index value from keys?
Code:
Map<String, Object> flattenedJsonMap = JsonFlattener.flattenAsMap(response.readEntity(String.class));
Map<String,Object> keysMap = new HashMap<>();
flattenedJsonMap.forEach(
(k, v) -> keysMap.put(k, v)
);
for (String kval : keysMap.keySet()) {
if (kval.contains("paper_id")) {
System.out.println("\nkval="+kval+"\n"+keysMap.get(kval));
}
}
Sample output
kval=[3].paper_id
01e3b313e78a352593be2ff64927192af66619b5
kval=[1].paper_id
004f0f8bb66cf446678dc13cf2701feec4f36d76
kval=[2].paper_id
01d162d7fae6aaba8e6e60e563ef4c2fca7b0e18
Wanted to get the total or get the index values (1,2,3 etc) from key ([1].paper_id)