public static String jsonParamNameFirstOneConvert(String str, Integer rule) {
String splitRule0 = "", splitRule1 = ":", splitRule2 = ",\"", splitRule3 = "\"", splitRule4 = "{", splitRule5 = "[";
String[] split = str.split(splitRule1);
List<String> params = new LinkedList<>();
for (int i = 0; i < split.length; i++) {
if (i == (split.length - 1)) {
break;
}
String[] ss = split[i].split(splitRule2);
String result = ss[ss.length - 1].replace(splitRule3, splitRule0).replace(splitRule4, splitRule0).replace(splitRule5, splitRule0);
params.add(result);
}
for (String param : params) {
String newParam = null;
if (rule.equals(1)) {
newParam = toUpperCaseFirstOne(param);
} else {
newParam = toLowerCaseFirstOne(param);
}
str = str.replace(param, newParam);
}
return str;
}
依赖方法 : 字符串(1) : 首字母转大写/小写_Lxinccode的博客-CSDN博客
更多字符串处理可以参考 : Java 常用工具类(22) : 字符串处理_Lxinccode的博客-CSDN博客
END。