java去掉json字符串中双引号

这篇博客主要介绍如何在Java中去除JSON字符串中的双引号。内容涉及字符串处理,包括空格去除和特定字符替换,以实现JSON格式转换。示例中展示了对包含HTML元素的复杂字符串进行处理的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在防控新型冠状病毒感染肺炎疫情工作中,全市水务系统把发挥党员的先锋模范作用作为践行初心、担当使命的重要抓手,第一时间落实我市关于抽调干部到社区参与新型冠状病毒感染的肺炎疫情防控工作的相关要求,积极动员全系统党员干部自愿参与社区一线防疫工作。</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: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);">在详细了解疫情防控工作情况后,1月27日起,水务系统志愿者即与相关区县党员干部和村社区工作者共同开展出入人员登记、体温检测、防疫知识宣传、外来人员信息摸排统计、值守居家隔离人员等工作。&nbsp;一是突出重点再排查。在前期摸排的基础上,配合社区进行入户排查,共走访排查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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值