package com.cowr.common.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; public class JsonUtil { public static JSONObject key2Lower(JSONObject obj) { return key2Lower(obj, false); } /** * json 对象 key 转小写 * * @param obj * @param deep * @return */ public static JSONObject key2Lower(JSONObject obj, boolean deep) { if (obj == null || obj.isEmpty()) { return obj; } JSONObject out = new JSONObject(); for (String key : obj.keySet()) { Object tmp = obj.get(key); if (tmp instanceof JSONObject && deep) { tmp = key2Lower((JSONObject) tmp, deep); } else if (tmp instanceof JSONArray && deep) { JSONArray arr = (JSONArray) tmp; for (int i = 0; i < arr.size(); i++) { arr.set(i, key2Lower(arr.getJSONObject(i), deep)); } } out.put(key.toLowerCase(), tmp); } return out; } }