private static String tmp = "{\"data\":{\"vin\":\"LNBSCCAK9JD065606\",\"extParameter\":{\"systemTime\":\"2019-01-23 12:58:35\",\"fuelAmount\":20.0},\"pushType\":\"fuelWarn\"},\"type\":\"uaes-iot-public-service\"}";
public static void main(String[] args) {
JSONObject jsonObject = JSON.parseObject(tmp);
JSONObject data = JSON.parseObject(jsonObject.getString("data"));
// line 1
Map<String, String> result = (Map<String, String>) data.getInnerMap().get("extParameter");
for (Map.Entry<String, String> item: result.entrySet()) {
String key = item.getKey();
// line 2
String value = item.getValue();
}
}
Above code throws a
ClassCastExecption at line 2: java.math.BigDecimal cannot be cast to java.lang.String
But the result type is acutally Map[String, String] , if the map's Value Type is not String, why is ClassCastExecption thrown at line 1?