C # Json serialization and deserialization two

Source: Internet
Author: User
<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)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.