LoginSignup
0
0

More than 5 years have passed since last update.

有意思的代码:

Posted at

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;
}
}
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0