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与类互转