我有一个Map<String,Integer>
我想要以下形式[{text: String, count: Integer},{text: String2, count: Integer2},...]
我知道如何用 python 中的理解来做这些事情,但以前从未将 Jackson 用于 java,我现在需要起诉。
我这样做是为了将地图转换为 Json
ObjectMapper mapper = new ObjectMapper();
try {
System.out.println(mapper.writeValueAsString(myMap));
//(looks like {"word":1,"word2":2,"word3":5}) (so I need to add a label text:
// before each word a label weight before each number and put each word/number
// block in a separate {})
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}