1. 程式人生 > 實用技巧 >C#_.Net Json轉Xml

C#_.Net Json轉Xml

 1     public  class XmlHelper
 2     {
 3         /// <summary>
 4         /// Json轉Xml格式
 5         /// </summary>
 6         /// <param name="strJson"></param>
 7         /// <returns></returns>
 8         public static string JsonToXml(string strJson)
 9         {
10             string
Xml = ""; 11 XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(strJson), XmlDictionaryReaderQuotas.Max); 12 XmlDocument doc = new XmlDocument(); 13 doc.Load(reader); 14 Xml = doc.InnerXml; 15 return
Xml; 16 } 17 }
View Code
 1         /// <summary>
 2         /// 獲取使用者 呼叫
 3         /// </summary>
 4         /// <param name="mid"></param>
 5         /// <returns></returns>
 6         [HttpGet]
 7         public IActionResult GetUserByLambda(string mid = "123")
8 { 9 var a = _userService.GetUsersByLambda(x => x.ManufacturerId.Equals(mid)); 10 var c = JsonHelper.SerializeJSON(a); 11 var b = XmlHelper.JsonToXml(c); 12 return Ok(b); 13 }
View Code

結果