c#转换XML文件和json对象
创建.XML文件
string xml = @"<?xml version=""1.0"" standalone=""no""?> <root> <person id=""1""> <name>Alan</name> <url>http://www.jb51.net</url> </person> <person id=""2""> <name>Louis</name> <url>http://www.jb51.net</url> </person> </root>";
c#将.xml文件与json对象之间相互转换
namespace DataProvider { public class MarketBarometer : IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { string path = AppDomain.CurrentDomain.BaseDirectory + "Data.xml"; XElement data = XElement.Load(path); //XML to JSON string dataObj = JsonConvert.SerializeXNode(data); //JSON to XML //XDocument dataDom = JsonConvert.DeserializeXNode(dataObj); context.Response.Write(dataObj); } } }