【发布时间】:2014-09-24 15:01:05
【问题描述】:
我的 Android 应用程序正在从 google places api 接收 json。在该评级通常是浮点值。所以当我在下面的代码中收到这个作为双数据类型的评级时,它说 HashMap 类型中的方法 put(String, String) 是不适用于参数(字符串,双精度)。所以我需要将此 p.rating 转换为字符串,以便将 hashmap 添加到 arraylist 以将其作为键、值对传递。我该如何实现。
// loop through each place
for (Place p : nearPlaces.results) {
HashMap<String, String> map = new HashMap<String,String>();
map.put(KEY_REFERENCE, p.reference);
// Place name
map.put(KEY_NAME, p.name);
map.put(KEY_EXTRA,p.rating);//here it says The method put(String, String) in the type HashMap<String,String> is not applicable for the arguments (String, double)
// adding HashMap to ArrayList
placesListItems.add(map);
}
【问题讨论】:
-
String.valueOf("p.rating")?