C#_.Net Json轉Xml
阿新 • • 發佈:2021-01-19
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 stringView CodeXml = ""; 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 returnXml; 16 } 17 }
1 /// <summary> 2 /// 獲取使用者 呼叫 3 /// </summary> 4 /// <param name="mid"></param> 5 /// <returns></returns> 6 [HttpGet] 7 public IActionResult GetUserByLambda(string mid = "123")View Code8 { 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 }
結果