java之json去掉转义字符

{
    "jdytrip_products_detail_response": {
        ......
       "feature": "{\"title\":\"线路特色\",\"detail\":\"

临安因为爱情主题酒店临安因为爱情主题酒店位于河桥镇政府向前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": "

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



"
}, ...... } }

更新一个更简便的方式:

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}

你可能感兴趣的:(Java)