1 循环取map里的value:eg: map {k1 : {k2:v2}}
input: map k1 , k2 output: v2
public static Object getValue(Map map, String... keys) {
if (map == null) {
return null;
} else {
for (int i = 0; i < keys.length - 1; ++i) {
if (!map.containsKey(keys[i]) || map.get(keys[i]) == null || map.get(keys[i]) == JSONObject.NULL) {
return null;
}
map = (Map) map.get(keys[i]);
}
if (map.containsKey(keys[keys.length - 1]) && map.get(keys[keys.length - 1]) != null && map.get(keys[keys.length - 1]) != JSONObject.NULL) {
return map.get(keys[keys.length - 1]);
} else {
return null;
}
}
}```