<summary>///Convert object to JSON string///</summary>//<typeparam name= "T" ></typep aram>//<param name= "input" ></param>///<returns></returns> public stat IC string scriptserialize<t> (T input) {string _jsonstring = string. Empty; if (input! = null) {JavaScriptSerializer _serializerhelper = new JavaScriptSerializer (); _serializerhelper.maxjsonlength = Int. MaxValue; _jsonstring = _serializerhelper.serialize (input); } return _jsonstring; }///<summary>//Convert the specified JSON string to an object of type T///</summary>//<typeparam name = "T" ></typeparam>//<param name= "input" ></param>//<returns></returns> public static T scriptdeserialize<t> (string input) {T RTN = default (t); if (!string. IsNullOrEmpty (Input)) {JavaScriptSerializer _serializerhelper = new JavaScriptSerializer (); RTN = _serializerhelper.deserialize<t> (input); } return RTN; } #region use JavaScriptSerializer to serialize objects into JSON///<summary>//Use JavaScriptSerializer to serialize objects into JSON Strings///</summary>//<typeparam name= "T" > Generics </typeparam>//<param name= "Entit Ylist "> Objects collection </param>//<returns>json</returns> public static string serialize<t> (ienumerable<t> entitylist) where T:class {string _jsonstring = string. Empty; if (entitylist! = null) {JavaScriptSerializer _serializerhelper = new JavaScriptSerializer (); _serializerhelper.maxjsonlength = Int. MaxValue; _jsonstring = _serializerhelper.serialize (entitylist); } return _jsonstring; } #endregion #region use JavaScriptSerializer to deserialize the JSON string///<summary>//Use Javascriptser Ializer to deserialize a JSON string///</summary>//<typeparam name= "T" > Generics </typeparam>//<p Aram Name= "jsonstring" ></param>///<returns>IEnumerable</returns> public static Ienume Rable<t> deserialize<t> (String jsonstring) where T:class {ienumerable<t> _list = Nu ll if (!string. IsNullOrEmpty (jsonstring)) {JavaScriptSerializer _serializerhelper = new JavaScriptSerializer () ; _list = _serializerhelper.deserialize<ienumerable<t>> (jsonstring); } return _list; } #endregion
C # Json serialization and deserialization of a
JOSN Serialization and deserialization demo
The above is the C # Json serialization and deserialization two content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!