替换字符串
1、原字符串,
string l_strResult = 你的字符串.Replace("\n", "").Replace(" ","").Replace("\t","").Replace("\r","");//去掉空格等
{"error":false,"data":[{"PartnerId":10000,"JobNoId":0,"BusinessType":2,"InsUsedCount":0,"LastDamagedCI":0,"Remark":"","InsSupplierId":9801,"init":false,"InsuranceNo":"PDAA201711020000058293","InsuranceSlipNo":"","InsPaperNo":"","InsSignPaperNo":"","InsuranceType":10,"BranchOrgId":0,"InsBeginTime":"0001-01-01","InsEndTime":"2018-03-03","SumBenchPremium":0,"Discount":0.28900122,"TotalPrice":508.83,"SumNetPremium":480.03,"BusinessWithCI":0,"TotalTax":28.8,"SignDate":"2018-01-02","CoefficientConfig":{"underwritingRate":0,"channelRate":0},"CarInfo":{"VehicleLicenceCode":"京A88888","isNewCar":0,"EngineNo":"BWR017524","VehicleClassCode":"1","VehicleFrameNo":"SCBBE53W88C057020","AutoModelCode":"BLCAAI0005","AutoModelName":"宾利飞驰CONTINENTAL FLYING SPUR轿车","ExtBrand":"宾利飞驰CONTINENTAL FLYING SPUR轿车","VehicleTypeCode":"A01","VehicleTypeDetailCode":"客车","LicenseColor":"蓝","CarPrice":3380000,"UsageAttribute":2,"UsageAttributeDetailCode":"212","VehicleSeats":"5","VehicleTonnages":"0","VehWholeWeight":2530,"Power":"5.9980","ExhaustCapability":"5.9980","LicenceTypeCode":"小型汽车号牌","FirstRegisterDate":"2010-03-05","OwnershipAttribute":4,"TransferCar":1},"UserList":[{"UserType":128,"PartnerId":9801,"RealName":"东方财富置业有限公司","OutUserId":"1100200000062238","CertificateType":25,"CertificateNO":"733466545","Address":"北京市东城区朝阳门北大街7号C座11层","Telephone":"","Mobile":"","Sex":0,"RolePalyer":"投保人,被保人,车主"}],"Items":[{"InsDetailId":10002,"InsSupplierDetailId":"050602","InsDetailName":"第三者责任保险","InsCoverage":500000,"InsDefAmount":1531,"InsAmount":442.46,"InsDiscount":0.289,"InsTax":0,"UnitAmount":0,"InsQuantity":1,"InsEx":"{\"coachCarFlag\":true,\"specialCheck\":false}"},{"InsDetailId":30002,"InsSupplierDetailId":"050931","InsDetailName":"不计免赔险(三者险)","InsCoverage":0,"InsDefAmount":229.65,"InsAmount":66.37,"InsDiscount":0.289,"InsTax":0,"UnitAmount":0,"InsQuantity":1,"InsEx":""}],"ExtInfo":"","AgentInfo":"{\"AgentCode\":\"11003O100177\",\"AgentName\":\"\"}","bizNoBZ":"","InsSaleInfo":{}},{"PartnerId":10000,"JobNoId":0,"BusinessType":2,"InsUsedCount":0,"LastDamagedCI":0,"Remark":"","InsSupplierId":9801,"init":false,"InsuranceNo":"PDZA201711020000060242","InsuranceSlipNo":"","InsPaperNo":"","InsSignPaperNo":"","InsuranceType":10,"BranchOrgId":0,"InsBeginTime":"0001-01-01","InsEndTime":"2018-03-03","SumBenchPremium":0,"Discount":0.7,"TotalPrice":611.54,"SumNetPremium":576.92,"BusinessWithCI":0,"TotalTax":34.62,"SignDate":"2018-01-02","CoefficientConfig":{"underwritingRate":0,"channelRate":0},"CarInfo":{"VehicleLicenceCode":"京A88888","isNewCar":0,"EngineNo":"BWR017524","VehicleClassCode":"1","VehicleFrameNo":"SCBBE53W88C057020","AutoModelCode":"BLCAAI0005","AutoModelName":"宾利飞驰CONTINENTAL FLYING SPUR轿车","ExtBrand":"宾利飞驰CONTINENTAL FLYING SPUR轿车","VehicleTypeCode":"A01","VehicleTypeDetailCode":"客车","LicenseColor":"蓝","CarPrice":3380000,"UsageAttribute":2,"UsageAttributeDetailCode":"212","VehicleSeats":"5","VehicleTonnages":"0","VehWholeWeight":2530,"Power":"5.9980","ExhaustCapability":"5.9980","LicenceTypeCode":"小型汽车号牌","FirstRegisterDate":"2010-03-05","OwnershipAttribute":4,"TransferCar":1},"UserList":[{"UserType":128,"PartnerId":9801,"RealName":"东方财富置业有限公司","OutUserId":"1100200000062238","CertificateType":25,"CertificateNO":"733466545","Address":"北京市东城区朝阳门北大街7号C座11层","Telephone":"","Mobile":"","Sex":0,"RolePalyer":"投保人,被保人,车主"}],"Items":[],"ExtInfo":"","AgentInfo":"{\"AgentCode\":\"11003O100177\",\"AgentName\":\"\"}","bizNoBZ":"","InsSaleInfo":{}}]}
2、替换,以,CoefficientConfig开头和}结尾的字符串

responseStr = responseStr.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", ""); string _configPattern = ",\"CoefficientConfig[^}]*}"; responseStr = Regex.Replace(responseStr, _configPattern,"");
3、去除所有的HTML标签
using System.Text.RegularExpressions; //需要引用 public string HtmlFilter(string strHtml) //从字符串里删除HTML { Regex regex = new Regex("<[^>]*>", RegexOptions.IgnoreCase); string strOutput = regex.Replace(strHtml, ""); return strOutput; }

浙公网安备 33010602011771号