/// <summary> /// 将字符串转换为Files字段数据类型 /// </summary> /// <param name="data"></param> /// <returns></returns> public static Pictures Parse(string data) { if (data == "") { return(null); } Pictures files = new Pictures(); List <Picture> list = new List <Picture>(); if (data.Substring(0, 1) == "[") { list = data.ParseJson <List <Picture> >(); } else if (data.Substring(0, 1) == "{") { Picture pic = data.ParseJson <Picture>(); if (list == null) { return(null); } } if (list == null) { return(null); } if (list.Count == 0) { try { list.Add(data.ParseJson <Picture>()); } catch { } } // foreach (Picture file in list) { if (file.isDel == 0) { files.Add(file); } else { #region 除无效文件 string path = Tools.MapPath("~" + file.path); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } string minpath = Tools.MapPath("~" + file.minPath); if (System.IO.File.Exists(minpath)) { System.IO.File.Delete(minpath); } #endregion } } if (files.Count > 0) { #region 设置默认值 files.title = files[0].title; files.path = files[0].path; files.title = files[0].title; files.isDel = files[0].isDel; files.minPath = files[0].minPath; #endregion } return(files); }
/// <summary> /// 将字符串转换为Files字段数据类型 /// </summary> /// <param name="data"></param> /// <returns></returns> public static Pictures Parse(string data) { Pictures files = new Pictures(); List <Picture> list = new List <Picture>(); try { list = data.ParseJson <List <Picture> >(); if (list == null) { return(null); } }catch { return(null); } if (list.Count == 0) { try { list.Add(data.ParseJson <Picture>()); } catch { } } // try { foreach (Picture file in list) { if (file.isDel == 0) { files.Add(file); } else { #region 除无效文件 try { string path = HttpContext.Current.Server.MapPath("~" + file.path); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } string minpath = HttpContext.Current.Server.MapPath("~" + file.minPath); if (System.IO.File.Exists(minpath)) { System.IO.File.Delete(minpath); } } catch { } #endregion } } } catch { } if (files.Count > 0) { #region 设置默认值 files.title = files[0].title; files.path = files[0].path; files.title = files[0].title; files.isDel = files[0].isDel; files.minPath = files[0].minPath; #endregion } return(files); }