【发布时间】:2015-10-08 20:58:31
【问题描述】:
当我进入第二个循环时,我正在寻找一种方法来获取特定键的值。我正在使用snakeyaml 并将其加载到地图中。我的 yaml 看起来像这样:
number:
id: status.number
label: Number
contactType:
id: status.contact_type
label: Contact Type
我正在尝试做的只是获取 id 的键和值。这可能非常明显,但我还没有找到这样做的方法。
Map<String, Map<String, String>> a = (Map<String, Map<String, String>>) yaml.load(input);
for (Map.Entry<String, Map<String, String>> t : a.entrySet()) {
String key = t.getKey();
for (Map.Entry<String, String> e : t.getValue().entrySet()) {
System.out.println("OuterKey: " + key + " InnerKey: " + e.getKey() + " VALUE:" + e.getValue());
}
}
【问题讨论】:
-
代替你的内循环:
t.getValue().get("id")?