我有以下使用org.json.simple创建JSON对象的函数。
public JSONObject createJSONRequest() {
// /* Create JSON Objects */
JSONObject jsonObject = new JSONObject();
Map<String, String> map = new HashMap<String, String>();
map.put(ACCESS_TOKEN_KEY, mAccessToken);
map.put(SESSION_ID_KEY, mSessionId);
map.put(SNAPZ_ID_KEY, mSnapzId);
map.put(EMAIL_KEY, mEmail);
map.put(EMAIL_PWD_KEY, mEmailPwd);
JSONArray list = new JSONArray();
list.add(map);
jsonObject.put("parameters", list);
jsonObject.put("function", "verifyEmail");
return jsonObject;
}然而,当我使用lint checker时,我一直收到这个警告。
[unchecked] unchecked call to add(E) as a member of the raw type ArrayList
list.add(map);
^
where E is a type-variable: E extends Object declared in class ArrayList
warning: [unchecked] unchecked call to put(K,V) as a member of the raw type HashMap
jsonObject.put("parameters", list);
^
where K,V are type-variables:
K extends Object declared in class HashMap
V extends Object declared in class HashMap
warning: [unchecked] unchecked call to put(K,V) as a member of the raw type HashMap
jsonObject.put("function", "verifyEmail");我尝试使用泛型类型。HashMap使用泛型,但其他对象JSONObject JSONArray不使用泛型。
非常感谢您的建议,
发布于 2014-07-03 17:13:20
您会收到此警告,因为库在内部使用原始类型集合。要隐藏此警告,您可以使用@SuppressWarnings("unchecked")注释您的方法。
如果您想使用具有泛型支持json库。你可以去找Google GSOn。我自己也在很多项目中使用过它。它很简单,并且使用泛型集合。
https://stackoverflow.com/questions/24548656
复制相似问题