[No00009A]JsonToObject json与类互转

using System.Web.Script.Serialization;

/// <summary> /// 内部类,保存jsonData /// </summary> public class JsonData { private string _userName; private string _userPassword; public bool IsStoreUserName { get; set; } public bool IsStoreUserPassword { get; set; } public string UserName { get { return IsStoreUserName ? _userName : ""; } set { _userName = IsStoreUserName ? value : ""; } } public string UserPassword { get { return IsStoreUserPassword ? _userPassword : ""; } set { _userPassword = IsStoreUserPassword ? value : ""; } } } #region JsonToObject json与类互转 // Object->Json public static string Serialize(JsonData obj) { JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); string json = jsonSerializer.Serialize(obj); return json; } // Json->Object public static JsonData Deserialize(string json) { JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); JsonData obj = jsonSerializer.Deserialize<JsonData>(json);//执行反序列化 return obj; } #endregion JsonToObject json与类互转

 

posted @ 2016-09-01 10:28  CharyGao  阅读(546)  评论(0编辑  收藏  举报