概述
今天在对接京东到家平台的时候取得的订单数据含有反斜杠,并且data数据是字符串类型的json格式的数据,数据中包含很多的反斜杠,完整数据如下:
{"code":"0","msg":"操作成功","data":"{"result":"{\"pageNo\":1,\"pageSize\":20,\"maxPageSize\":100,\"totalCount\":1,\"resultList\":[{\"orderId\":624573044000041,\"srcOrderId\":\"624573044000041\",\"srcPlatId\":4,\"srcOrderType\":0,\"srcInnerType\":0,\"srcInnerOrderId\":0,\"orderType\":10000,\"orderStatus\":90000,\"orderStatusTime\":\"2016-10-11 10:18:11\",\"orderStartTime\":\"2016-10-11 09:50:43\",\"orderPurchaseTime\":\"2016-10-11 09:50:57\",\"orderAgingType\":12,\"orderPreStartDeliveryTime\":\"2016-10-11 11:50:00\",\"orderPreEndDeliveryTime\":\"2016-10-11 11:50:00\",\"orderIsClosed\":true,\"orderCloseTime\":\"2016-10-11 10:18:11\",\"orgCode\":\"74554\",\"buyerPinType\":0,\"buyerPin\":\"JD_350u24a96522f\",\"buyerFullName\":\"王斌\",\"buyerFullAddress\":\"武汉市江汉区金雅公寓2栋1单元902室\",\"buyerMobile\":\"13720339384\",\"buyerProvince\":\"0\",\"buyerCity\":\"1381\",\"buyerCountry\":\"3582\",\"produceStationNo\":\"10055023\",\"produceStationName\":\"可多直营-汉兴小区店\",\"produceStationNoIsv\":\"0014\",\"deliveryStationNo\":\"10055023\",\"deliveryStationName\":\"可多直营-汉兴小区店\",\"deliveryStationNoIsv\":\"0014\",\"deliveryType\":1,\"deliveryCarrierNo\":\"9966\",\"deliveryCarrierName\":\"达达专送\",\"deliveryBillNo\":\"624573044000041\",\"deliveryPackageWeight\":1.7179999649524689,\"deliveryPackageVolume\":0,\"deliveryManName\":\"涂志学\",\"deliveryManPhone\":\"15926351698\",\"deliveryConfirmTime\":\"2016-10-11 10:18:10\",\"orderPayType\":4,\"orderTotalMoney\":7300,\"orderDiscountMoney\":500,\"orderFreightMoney\":200,\"orderBuyerPayableMoney\":7000,\"orderVenderChargeMoney\":0,\"packagingMoney\":0,\"orderBalanceUsed\":0,\"orderInvoiceOpenMark\":2,\"adjustIsExists\":false,\"adjustCount\":0,\"orderFinanceOrgCode\":706,\"isJDGetCash\":true,\"adjustId\":0,\"orderJingdouMoney\":0,\"ts\":\"2016-10-11 10:18:11\",\"buyerCityName\":\"武汉市\",\"buyerCountryName\":\"江汉区\",\"buyerCoordType\":2,\"buyerLat\":30.6216,\"buyerLng\":114.244,\"buyerIp\":1001139541,\"orderBuyerRemark\":\"所购商品如遇缺货,您需要(门店默认配置):未缺货商品继续配送(缺货商品退款)\",\"businessTag\":\"dj_new_cashier;dj_aging_immediately;dj_bld;picking_up;\",\"equipmentId\":\"B8F4F80C-EBAD-4223-B666-1784E4F77F37\",\"buyerPoi\":\"金雅公寓\",\"product\":[{\"skuId\":2001716488,\"skuName\":\"潘婷乳液修护优惠装700ml/瓶\",\"skuIdIsv\":\"6903148204078\",\"skuSpuId\":0,\"skuJdPrice\":4900,\"skuCount\":1,\"skuStockOwner\":0,\"isGift\":false,\"adjustMode\":0,\"upcCode\":\"6903148204078\",\"categoryId\":\"21232,21233,22984\",\"skuStorePrice\":4900,\"promotionType\":1,\"promotionId\":17640,\"skuWeight\":0.7979999780654907,\"canteenMoney\":0},{\"skuId\":2001716594,\"skuName\":\"康师傅爆椒牛肉面98g/袋\",\"skuIdIsv\":\"6920734737901\",\"skuSpuId\":0,\"skuJdPrice\":300,\"skuCount\":2,\"skuStockOwner\":0,\"isGift\":false,\"adjustMode\":0,\"upcCode\":\"6920734737901\",\"categoryId\":\"20392,20949,20970\",\"skuStorePrice\":300,\"promotionType\":1,\"promotionId\":17640,\"skuWeight\":0.09799999743700027,\"canteenMoney\":0},{\"skuId\":2001716721,\"skuName\":\"统一来一桶老坛酸菜牛肉味面120g/桶\",\"skuIdIsv\":\"6925303773106\",\"skuSpuId\":0,\"skuJdPrice\":400,\"skuCount\":2,\"skuStockOwner\":0,\"isGift\":false,\"adjustMode\":0,\"upcCode\":\"6925303773106\",\"categoryId\":\"20392,20949,20952\",\"skuStorePrice\":400,\"promotionType\":1,\"promotionId\":17640,\"skuWeight\":0.11999999731779099,\"canteenMoney\":0},{\"skuId\":2001716726,\"skuName\":\"统一100老坛酸菜牛肉面121g/袋\",\"skuIdIsv\":\"6925303773915\",\"skuSpuId\":0,\"skuJdPrice\":250,\"skuCount\":4,\"skuStockOwner\":0,\"isGift\":false,\"adjustMode\":0,\"upcCode\":\"6925303773915\",\"categoryId\":\"20392,20949,20970\",\"skuStorePrice\":250,\"promotionType\":1,\"promotionId\":17640,\"skuWeight\":0.12099999934434891,\"canteenMoney\":0}],\"discount\":[{\"skuIds\":\"2001716594,2001716721,2001716488,2001716726\",\"discountType\":4,\"discountDetailType\":1,\"discountCode\":\"17640\",\"discountPrice\":500}],\"appVersion\":\"iOS3.4.0\",\"yn\":false,\"payChannel\":9002,\"isDeleted\":false,\"orderGoodsMoney\":7300,\"orderStockOwner\":3,\"orderSkuType\":0,\"isGroupon\":false,\"orderBaseFreightMoney\":200,\"orderLadderFreightMoney\":0,\"orderAdditionFreightMoney\":0,\"orderBaseReceivableFreight\":0,\"orderAcceptTime\":\"2016-10-11 09:51:00\",\"businessType\":1}],\"totalPage\":1,\"page\":1}","detail":"","code":"0","msg":"操作成功"}","success":true}
当直接用fastjson进行解析时报错如下:
我的代码写法如下:
,后来通过如下方式解决:
先看结果图:
解决代码如下:
JSONUtil类:
上面通过先转成map这种方式应该是可靠的。在解决问题的时候,有个朋友说用new String(result)试下,我就试了下,结果也可以,就是上面代码的aaa的输出,然后让另一个同学试了下,他那用new的方式还是会报最初的转换错误,具体原因不太清楚,不知道这两种String到底有什么区别,还请各位大神指点下。
最后
以上就是活泼人生为你收集整理的解析带有反斜杠的json数据的全部内容,希望文章能够帮你解决解析带有反斜杠的json数据所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复