Created
June 27, 2014 18:06
-
-
Save kenu/3b3f86200fdecbae6a66 to your computer and use it in GitHub Desktop.
Commons Note
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#frm").serialize().split("&").sort(); | |
private static final Logger logger = LoggerFactory.getLogger(Commons.class); | |
public static void writeJSON(HttpServletResponse response, | |
final String label, final Object data) { | |
JSONObject jsonObj = new JSONObject(); | |
jsonObj.put(label, data); | |
response.setContentType("application/json; charset=UTF-8"); | |
response.setHeader("Cache-Control", "no-cache"); | |
try { | |
response.getWriter().write( | |
JSONObject.fromObject(jsonObj).toString()); | |
} catch (IOException e) { | |
logger.debug(label, e); | |
} | |
} | |
public static void eraseNull(final List<Map<String, Object>> list) { | |
for (Map<String, Object> map : list) { | |
eraseNull(map); | |
} | |
} | |
public static void eraseNull(Map<String, Object> map) { | |
Set<String> keySet = map.keySet(); | |
for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) { | |
String string = iterator.next(); | |
if (map.get(string) == null) { | |
map.put(string, ""); | |
} | |
} | |
} | |
public static List<String> getArrayList(Map<String, Object> paramMap, | |
final String key) { | |
List<String> list = new ArrayList<String>(); | |
if (paramMap.get(key) instanceof String) { | |
list.add((String) paramMap.get(key)); | |
} else if (paramMap.get(key) instanceof String[]) { | |
String[] vlist = (String[]) paramMap.get(key); | |
for (int i = 0; i < vlist.length; i++) { | |
list.add(((String[]) paramMap.get(key))[i]); | |
} | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment