1 ??????????????XmlDocument doc = new XmlDocument(); 2 ????????????????doc.Load(path); 3 ????????????????string strXml = doc.InnerXml; 4 ????????????????XmlNode node = doc.SelectSingleNode("data"); ?//data ?根节点名称 5 ????????????????string result = Newtonsoft.Json.JsonConvert.SerializeXmlNode(node); 6 ?7 ?8 ????????????????//string pathFile = System.IO.Path.GetFullPath("../../file/josn.txt"); 9 ????????????????FileStream fs = new FileStream(@"../../file/josn.txt", FileMode.Create);10 11 ????????????????12 ????????????????//获得字节数组13 ????????????????byte[] data = System.Text.Encoding.Default.GetBytes(result); 14 ????????????????//开始写入15 ????????????????fs.Write(data, 0, data.Length);16 ????????????????//清空缓冲区、关闭流17 ????????????????fs.Flush();18 ????????????????fs.Close();
XML转JSON
原文地址:https://www.cnblogs.com/lq0418/p/9920652.html