Is it possible to inspect data type of value while iterating through HashMap<String,Object>
?
while(iterator.hasNext) {
Map.Entry pairs = (Map.Entry) iterator.next();
String key = pairs.getKey();
<Type> value = (Type) pairs.getValue();
}
The map has a combination of Boolean
, String
and ArrayList<String>
types as values. I would like to determine the data type of the value at runtime and properly cast it.
我建议您使用像Jackson或GSON这样的对象映射器在json和您的对象之间进行转换,而不要手动执行。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.