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 }
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 }
结果