在以下情况下需要帮助 - 使用 RestTemplate 我通过以下方式从内部服务器获得响应:
Map<String, String> response = RestTemplate.getForObject(url, Map.class);
响应的结构是:
"mainRate" -> 2.99000 // double
"secondaryRates" -> [{rateName -> r1, rateVal -> 5.9}] //ArrayList of LinkedHashMap<String, Double>
第一个问题 - 我无法以简单的方式从地图结果中读取:
double mainRate = response.get("mainRate")
这将给出 ClassCastException。不知道为什么?有人遇到过这种情况吗?相反,我这样做:
double mainRate = Double.parseDouble(String.valueOf(response.get("mainRate")));
请告知为什么简单的 response.get(keyName) 方法不起作用?它仅适用于转换为字符串然后加倍。
第二个问题是集合 - 如何解析对象的嵌套集合?