参数化JSONArray方法添加的正确方法



我正在尝试使用LinkedHashMap<字符串,对象>对象和一个JSON数组对象来生成如下的JSON字符串:

JSONArray json = new JSONArray();
LinkedHashMap<String, Object> data = new LinkedHashMap<String, Object>();
data.put("SomeKey",Object);
json.add(data);//Here jumps up the warning: (Type safety: The method add(Object) belongs to the raw type ArrayList. References to generic type ArrayList<E> should be parameterized)
/* More Code */
return json.toString();

我试图通过添加下一个代码来获得参数化数据:

json.add((LinkedHashMap<String,Object>)data);

但警告仍然存在。

我如何才能以良好的方式消除此警告?或者有更好的方法吗?

根据使用JSONArray和JSONObject时如何摆脱类型警告,唯一的方法是@SuppressWarnings("unchecked")

最新更新