将XML文件中的内容转换为Json对象

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using System.Windows.Forms;

namespace XmlToJsonDemo
{
class Program
{
static void Main(string[] args)
{
//将XML文件中的内容转换为Json对象
XmlDocument doc = new XmlDocument();
doc.Load(Application.StartupPath + @"XMLFile1.xml");
string jsonText = JsonConvert.SerializeXmlNode(doc);
Console.WriteLine(jsonText);
Console.ReadKey();

}
}
}

Newtonsoft.Json动态库需要单独下载

原文地址:https://www.cnblogs.com/Robert-huge/p/5527407.html