/// <summary> /// xml字符串转换成对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="xmlStr"></param> /// <returns></returns> public T XMLStringToObject<T>(string xmlStr) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlStr); //加载xml文件 //去掉头 doc.RemoveChild(doc.FirstChild); string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc).Replace("@",""); //选择开始解析的节点 if (json.StartsWith("{\"response\"")) { JObject obj = JObject.Parse(json); json = obj.GetValue("response").ToString(); } //转化为对象 Type t = typeof(T); var entiy = Activator.CreateInstance(t); entiy = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json); return (T)entiy; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。