ssjygl-xsct-service/ssjygl-xsx-common/src/main/java/com/cowr/common/utils/JsonUtil.java

40 lines
1.0 KiB
Java
Raw Normal View History

2020-08-07 17:11:12 +08:00
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;
}
}