java之json去掉轉義字元
阿新 • • 發佈:2019-01-25
{
"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>【真純玩】銷售冠軍,直營團,不加水、不進店、無購物,不推銷, <br/>【發團快】劃片區直髮,各片區獨立成團,勿需中轉換乘,最快發團,最早回程,遊覽時間多出1小時<br/>【包接】解除路不熟、打車難的苦惱,輕鬆到家<br/>【豪華土家宴】仙女山星級酒店提供“農家八大碗”,非農家樂用餐環境可比 <br/>【導遊好】親媽般呵護、保姆級照顧,不催促、不趕路、配耳麥講解 <br/>【不換乘】專享綠色通道,天坑入口、地縫出口無需排隊換車,減少舟車勞頓 <br/>【贈品多】提供自拍杆、充電寶、礦泉水、雨衣(視天氣)<br/>市場同類產品對比 <br/>自營團 其它團<br/>【發團】 不換車,快發團√ 需集散換車× <br/>【用餐】 豪華土家宴√ 農家樂桌餐× <br/>【購物】 堅決不進店√ 加水點購物× <br/>【導遊】 好評導遊耳麥講解√ 推銷較多×</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}