1.去掉字符串中的空格
2.去掉字符双引号
字符串{"fBNR":"<p style="text-align: center;"><span style="color: rgb(85, 85, 85); font-family: 仿宋; text-align: center; background-color: rgb(255, 255, 255);">——市水务系统志愿者助力包挂社区疫情防控工作</span></p><p><span style="color: rgb(85, 85, 85); font-family: 仿宋; text-align: center; background-color: rgb(255, 255, 255);"><span style="color: rgb(85, 85, 85); font-family: "Microsoft Yahei", "Helvetica Neue", Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);"> 在防控新型冠状病毒感染肺炎疫情工作中,全市水务系统把发挥党员的先锋模范作用作为践行初心、担当使命的重要抓手,第一时间落实我市关于抽调干部到社区参与新型冠状病毒感染的肺炎疫情防控工作的相关要求,积极动员全系统党员干部自愿参与社区一线防疫工作。</span></span></p><p><span style="color: rgb(85, 85, 85); font-family: 仿宋; text-align: center; background-color: rgb(255, 255, 255);"><span style="color: rgb(85, 85, 85); font-family: "Microsoft Yahei", "Helvetica Neue", Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);"> <span style="color: rgb(85, 85, 85); font-family: "Microsoft Yahei", "Helvetica Neue", Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);">在详细了解疫情防控工作情况后,1月27日起,水务系统志愿者即与相关区县党员干部和村社区工作者共同开展出入人员登记、体温检测、防疫知识宣传、外来人员信息摸排统计、值守居家隔离人员等工作。 一是突出重点再排查。在前期摸排的基础上,配合社区进行入户排查,共走访排查10余个小区,3000余户住户"}
//去空格 public String replaceBlank(String str) { String dest = ""; if (str != null) { Pattern p = Pattern.compile("\\s*|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(""); // Pattern p2 = Pattern.compile("\\s*\""); // Matcher m2 = p2.matcher(dest); // dest = m2.replaceAll("\'"); dest = dest.replace("=\"", "='"); p = Pattern.compile("\"\0*>"); m = p.matcher(dest); dest = m.replaceAll(">'"); } return dest; }
//去双引号 public String jsonStringConvert(String s) { char[] temp = s.toCharArray(); int n = temp.length; for (int i = 0; i < n; i++) { if (temp[i] == ':' && temp[i + 1] == '"') { for (int j = i + 2; j < n; j++) { if (temp[j] == '"') { if (temp[j + 1] != ',' && temp[j + 1] != '}') { temp[j] = '”'; } else if (temp[j + 1] == ',' || temp[j + 1] == '}') { break; } } } } } return new String(temp); }