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