【发布时间】:2015-12-10 11:12:24
【问题描述】:
我在我的项目中使用 java。当我尝试从 json 对象获取密钥时,我收到以下警告:Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator 我试图通过@SupressWarning('unchecked') 修复,但 Eclipse 仍然在文件中显示警告。我不知道出了什么问题。
public static HashMap<String, String> jsonToMap(final JSONObject jsonMap)
throws JSONException {
HashMap<String, String> map = new HashMap<String, String>();
Iterator<Object> keys = jsonMap.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
String value = jsonMap.getString(key);
map.put(key, value);
}
return map;
}
【问题讨论】: