private string ConverXml(string memberId, int code, string msg)

       {

           var resp = new { authenticate = new { member_id = memberId, status_code = code, message = msg } };

           var jsonstr = JsonConvert.SerializeObject(resp);

           XmlDocument doc = JsonConvert.DeserializeXmlNode(jsonstr);

           XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");

           XmlElement root = doc.DocumentElement;

           doc.InsertBefore(xmldecl, root);

           return doc.InnerXml;

       }

返回XML


C# JSON字符串转带头(声明)XML字符串_json


参考地址:https://www.yzktw.com.cn/post/1160585.html

https://devbox.cn/p/106706727

http://md5.cn/tools/json2xml/