expressUrl = string.Format(可以卸载配置文件的域名URL + "/bsp-oisp/ws/expressService"); StringBuilder sbParams = new StringBuilder(); sbParams.AppendLine("<Request service='RouteService' lang='zh-CN'>"); sbParams.AppendLine("<Head>"); sbParams.AppendLine(这里是顺丰提供的客户秘钥); sbParams.AppendLine("</Head>"); sbParams.AppendLine("<Body>"); sbParams.AppendLine("<RouteRequest tracking_type='1' method_type='1' tracking_number='" + 运单号 + "'/>"); sbParams.AppendLine("</Body>"); sbParams.AppendLine("</Request>"); SFexpressService.ServiceClient sfService = new SFexpressService.ServiceClient(); //调用顺丰的webapi接口 expressResult = sfService.sfexpressService(sbParams.ToString()); XmlDocument doc = new XmlDocument(); doc.LoadXml(expressResult); //这里把xml转换成JSON,但是直接SerializeXmlNode调用这个方法就会导致很多属性中存在@符号,网上找到的方案是正则替换 expressResult = Regex.Replace(JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.None), "(?<=")(@)(?!.*":\s )", string.Empty, RegexOptions.IgnoreCase); //这里是正则替换的结果怕属性值?xml有问题,再替换成一个自己定义的值 expressResult = expressResult.Replace("?xml","expressXml");