如何在 Java 中创建具有多种数据类型的嵌套哈希图?

How to create a nested hashmap with multiple datatypes in Java?

我需要得到这样的输出:

[
 {
   "index": 2,
   "range": true,
   "label": { 
              "Label1":"Value1",
              "Label2":"Value2"
            }
 }
]

值与整数布尔值和 map 的组合

在 Python 中,我们可以简单地使用列表和字典来完成,但我如何在 Java 中实现这一点?

您所描述的结构似乎是这样的:

List.of(Map.of(
    "index", 2,
    "range", true,
    "label", Map.of("Label1", "Value1", "Label2", "Value2")
))

这是一个List<Map<String, Object>>