1:json的介绍:json常用于前台与后台的数据传输 传递时需将json对象转换为json字符 JSON.stringify();
2:json格式的查看应用:JsonView
3:后台获取到json字符格式的处理方式:
a:去除多余的字符
例子:
.Replace("\",\"", ",") .Replace("[\"", "[") .Replace("\"]", "]") .Replace("\\\"name\\\"", "name") .Replace("\\\"type\\\"", "type") .Replace("\\\"url\\\"", "url") .Replace("\\\"key\\\"", "key") .Replace("\\\"subbutton\\\"", "subbutton") .Replace("\"button\"", "button") .Replace("\\\"", "\"");
b:序列化和反序列化
b1:序列化 public static string Serialize(object pObject) { return JsonConvert.SerializeObject(pObject); } b2.1:反序列化为对象 public static T Deserialize<T>(string pJsonData) { return JsonConvert.DeserializeObject<T>(pJsonData); } b2.2:反序列化为集合 public static List<T> JSONStringToList<T>(this string JsonStr) { JavaScriptSerializer Serializer = new JavaScriptSerializer(); List<T> objs = Serializer.Deserialize<List<T>>(JsonStr); return objs; }