好久没有写博客了,最近的笔记都整理到印象笔记了,等有时间了再移到优快云吧。
今天写一下FastJSON。
FastJSON处理大的JSON对象或数组时,单纯用JSONObject、JSONArray的API不利于性能。
比如反序列化Map对象对应的JSON String。
JSONObject responseJSONObject;
try {
responseJSONObject = JSON.parseObject(new String(response, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return;
}
for (Object object : responseJSONObject.entrySet()) {
Map.Entry<String, JSONObject> objectMapEntry = (Map.Entry<String, JSONObject>) object;
map.put(objectMapEntry.getKey(), JSON.parseObject(objectMapEntry.getValue().toJSONString(), Map的Value对应的类.class));
}
这种方式不够快。
来个快的,在工作中的场景快了三分之二:
private <T> Map<String, T> getNormalMap(Class<T> clazz, byte[] response){
Map<String, T> map = new HashMap