public static String toGridJSONString(List objectList, String attributes) {
if (objectList == null)
return null;
if (objectList.size() == 0)
return "";
JSONArray arrayValue = new JSONArray();
JSONObject oJson;
try {
arrayValue = toJSONArray(objectList, attributes,0);
oJson = new JSONObject();
oJson.put("totalPage", arrayValue.size());
oJson.put("data", arrayValue);
return oJson.toString();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
系统提示 JSONArray arrayValue = new JSONArray();这行Dead store to local variable
是因为 arrayValue = toJSONArray(objectList, attributes,0);有重新实例化了对象arrayValue ,前一个 new JSONArray();是没有必要的。这样会消耗资源。