public static class JsonAdapter<T> where T : class { public static string ToJson(T obj) { return JsonAdapter.ToJson(obj); } } public static class JsonAdapter { public static string ToJson(object o) { string result = ""; if (o != null) { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = serializer.MaxJsonLength * 100; result = serializer.Serialize(o); } return result; } public static object FromJsonAsDictionary(string jsonstr) { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = serializer.MaxJsonLength * 100; if (jsonstr == null) jsonstr = ""; return serializer.DeserializeObject(jsonstr) ?? new StringObjectDictionary(); } }
时间: 2024-10-01 09:54:20