关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

Newtonsoft.Json xml 转json 正确的方法 不会报错

发布时间:2019-10-30 16:37:46
 var postData = new Dictionary<string, string>  //提交的数据
                {
                    { "userid", sys_user},
                    { "versig", md5sing},
                    {"strCmd",cmdstrng}
                };
            var urlEncodedContent = new FormUrlEncodedContent(postData); //提交的数据进行编码
            var httpClient = new HttpClient(); //new 一个http客户端
            var result = httpClient.PostAsync(url, urlEncodedContent).Result.Content.ReadAsStringAsync().Result; //返回结果
            XmlDocument doc = new XmlDocument(); //new 一个xml文档 使之标准化不new 会出错哦
            doc.LoadXml(result); //吧结果加载到xml 文档里
            var jsonResult = JsonConvert.SerializeXmlNode(doc).ToString(); //这个方法很重要
            return jsonResult;

zqbb.jpg


/template/Home/Zkeys/PC/Static