Reprint--The article (thanks to the rice Bo Master share) about Json.NET serialization time problem

Source: Internet
Author: User
Tags net serialization

Http://www.cnblogs.com/lxsweat/p/4372508.html

on the Code

The use method and the UserInfo entity object are not affixed to the code.

        ///<summary> //////</summary> ///<param name= "O" > object </param> /// <returns>json string </returns> public static string Serializetojson (object data" {return 
Get Results (red font)
 var data ={"dbstring": "Test", "Modeluserinfo": {"user_id": 1002, "user_name": "[email protected]", "Real_name": "[email protected]", "Password": "96e79218965eb72c92a549dd5a330112", "Mobile": "13121893780", "Lng": 117.19381, "Precision": 0, "lastlogin_date": "/date (1417165362307)/" , "create_date": "/date (1417104000000)/" ,// time will be in this format "CREATE_IP": "127.0.0.1"       
Method Optimization

Overloaded parameters are added to the SerializeObject method
var timeconverter = new Isodatetimeconverter {DateTimeFormat = datetimeformats};

        String Serializetojson ("yyyy-mm-dd HH:mm:ss"new Isodatetimeconverter {DateTimeFormat =  return jsonconvert.serializeobject (data, formatting.indented, TimeConverter);}     

Other methods
        ///<summary>///Convert a JSON string to a solid object///</summary>///<typeparam name= "T" >Object</typeparam>///<param name= "Data" >JSON string</param>PublicStatic T deserializetomodel<t> (StringData) {Return jsonconvert.deserializeobject<t>(data); }///<summary> ///<t> /// </summary> /// <typeparam name= "T" ></typeparam> ///< param name= "Data" ></param> ///<returns ></returns> public static list<t> Deserializetolist<t> (string data) {return jsonconvert.deserializeobject<list<t>>   

Note: There may be a problem when converting a JSON list string to list<t>. Look below the modeluser_infolist is a list of entity lists, however the preceding code and MSG belong to the custom field.

Call method:deserializetolist<t> (string data) Remember to take out the array passed in the data parameter

           Return Jsonutils.serializetojson (new            {                "1" "Success", data = modeluser_infolist});         

Example:

Jobject obj = jobject.parse (json_list);  String json = obj["data"]. ToString (); list<user_info> Listgetresultinfo = jsonutils.deserializetolist<user_info> (JSON);     

Original address: http://www.cnblogs.com/lxsweat/p/4372508.html

Reprint--The article (thanks to the rice Bo Master share) about Json.NET serialization time problem

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.