java之json去掉转义字符

{
    "jdytrip_products_detail_response": {
        ......
       "feature": "{\"title\":\"线路特色\",\"detail\":\"<p><span style=\\\"color: rgb(51, 51, 51); font-family: arial, 微软雅黑, sans-serif; font-size: 14px; line-height: 24px;\\\">临安因为爱情主题酒店临安因为爱情主题酒店位于河桥镇政府向前100米,房间配套设施齐全,交通便利,环境优雅,周边有柳溪江女人河、风情小镇、唐昌老街、温泉、瑞晶石花洞等旅游景点,因为爱情主题酒店以热情的服务期待你的光临!<\\/span><\\/p>\"}", 
 ......
  }
}

存入数据库时不想让带上\ 转义,

......
JdytripProductsDetailResponse response = ropClient.execute(request, session);
                if (response != null && response.isSuccess()) {
                    ProductDetail productDetail = new ProductDetail();
                    productDetail.setProductId(Long.parseLong(response.getP_id()));
                    Map<String,Object> map = new HashMap<String, Object>();
                    if (StringUtils.isNotNullOrEmptyStr(response.getFeature())) {

                        map.put("feature",JSON.parse(response.getFeature()).toString());
//                        log.info("============="+JSON.toJSONString(response.getFeature()));
                    }
                    if (StringUtils.isNotNullOrEmptyStr(response.getStroke())) {

                        map.put("stroke",JSON.parse(response.getStroke()));
                    }
                    if (StringUtils.isNotNullOrEmptyStr(response.getCost_in())) {

                        map.put("cost_in",JSON.parse(response.getCost_in()));
                    }
                    if (StringUtils.isNotNullOrEmptyStr(response.getCost_noin())) {

                        map.put("cost_noin",JSON.parse(response.getCost_noin()));
                    }
                    if (StringUtils.isNotNullOrEmptyStr(response.getNotice())) {

                        map.put("notice",JSON.parse(response.getNotice()));
                    }
                    productDetail.setContent(net.sf.json.JSONObject.fromObject(map).toString());
//                    log.info("================"+net.sf.json.JSONObject.fromObject(map).toString().getBytes().length);
                    productDetail.setTitle(response.getP_name());
                    productDetail.setVersion("1.0");
                    productDetailList.add(productDetail);
                }
......

存入数据库的内容

{
    "feature": {
        "title": "线路特色",
        "detail": "<p>【真纯玩】销售冠军,直营团,不加水、不进店、无购物,不推销,&nbsp;<br/>【发团快】划片区直发,各片区独立成团,勿需中转换乘,最快发团,最早回程,游览时间多出1小时<br/>【包接】解除路不熟、打车难的苦恼,轻松到家<br/>【豪华土家宴】仙女山星级酒店提供“农家八大碗”,非农家乐用餐环境可比&nbsp;<br/>【导游好】亲妈般呵护、保姆级照顾,不催促、不赶路、配耳麦讲解&nbsp;<br/>【不换乘】专享绿色通道,天坑入口、地缝出口无需排队换车,减少舟车劳顿&nbsp;<br/>【赠品多】提供自拍杆、充电宝、矿泉水、雨衣(视天气)<br/>市场同类产品对比&nbsp;<br/>自营团 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 其它团<br/>【发团】 不换车,快发团√ &nbsp; &nbsp; &nbsp;需集散换车×&nbsp;<br/>【用餐】 豪华土家宴√ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;农家乐桌餐×&nbsp;<br/>【购物】 坚决不进店√ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;加水点购物×&nbsp;<br/>【导游】 好评导游耳麦讲解√ &nbsp; &nbsp;推销较多×</p><p><br/></p><p><br/></p>"
    },
    ......
       }
}

更新一个更简便的方式:

String s1="{\"MsgId\":1,\"TotalCount\":10,\"FilterCount\":8,\"SentCount\":7,\"ErrorCount\":1}";
System.out.println(StringEscapeUtils.unescapeJava(s1));

输出:

{"MsgId":1,"TotalCount":10,"FilterCount":8,"SentCount":7,"ErrorCount":1}
  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

每天进步一点_点

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值