Map 中的键打印为[index].keyname。如何从键中获取索引值?
代码:
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));
}
}
样本输出
kval=[3].paper_id
01e3b313e78a352593be2ff64927192af66619b5
kval=[1].paper_id
004f0f8bb66cf446678dc13cf2701feec4f36d76
kval=[2].paper_id
01d162d7fae6aaba8e6e60e563ef4c2fca7b0e18
想要从键([1].paper_id)获取总数或获取索引值(1、2、3等)