using System.Xml.Serialization; using Newtonsoft.json;
XML transformations
/// <summary> ///XML Transformation entity class/// </summary> /// <typeparam name= "T" >entity classes corresponding to XML</typeparam> /// <param name= "res" >XML string</param> /// <returns>the failure returned null, and the corresponding T was successfully returned</returns> PublicT getxmlt<t> (stringReswhereR |class { Try{XmlSerializer Serializer=NewXmlSerializer (typeof(T)); StringReader RDR=NewStringReader (RES); T RT= Serializer. Deserialize (RDR) asT; returnRT; } Catch(Exception ex) {return NULL; } }
JSON conversion
/// <summary> ///JSON transform to get entity object/// </summary> /// <typeparam name= "T" >JSON-corresponding entity object</typeparam> /// <param name= "res" >JSON string</param> /// <returns>the failure returned null, and the corresponding T was successfully returned</returns> PublicT getjsont<t> (stringReswhereT:class { Try { returnJsonconvert.deserializeobject<t>(RES); } Catch(Exception ex) {return NULL; } }
XML, JSON deserialization gets the corresponding class