/// <summary> /// /// </summary> /// <param name="actionContext"></param> /// <param name="httpContext"></param> /// <returns></returns> public void GetGridData(ActionContext actionContext, HttpContext httpContext) { string otherUnid = httpContext.Request.Params["otherUnid"]; int pageNo = int.Parse(httpContext.Request.Params["pageNo"].Trim()); int pageSize = int.Parse(httpContext.Request.Params["pageSize"].Trim()); Newtonsoft.Json.JavaScriptObject jsonObject = new Newtonsoft.Json.JavaScriptObject(); jsonObject.Add("rows", new Newtonsoft.Json.JavaScriptArray()); jsonObject.Add("totalCount", 0); jsonObject.Add("id", "ID"); PageInfo pageInfo = this.userService.FindAllByRelationShipParentUnid(otherUnid, pageNo, pageSize); if (!string.IsNullOrEmpty(otherUnid)) { if (pageInfo != null) { IList list = pageInfo.Objs; if (!(list == null || list.Count == 0)) { Newtonsoft.Json.JavaScriptArray jsonArray = this.GetArray <User>(list); jsonObject["rows"] = jsonArray; jsonObject["totalCount"] = pageInfo.TotalCount; } } } httpContext.Response.ContentType = ("text/plain;charset=UTF-8"); httpContext.Response.AppendHeader("Cache-Control", "no-cache"); httpContext.Response.Write(Newtonsoft.Json.JavaScriptConvert.SerializeObject(jsonObject)); }
public List <T> ToList <T>(string json) { Newtonsoft.Json.JavaScriptArray jsonArray = (Newtonsoft.Json.JavaScriptArray)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(json); List <T> list = new List <T>(); T model = NewObject <T>(); System.Reflection.PropertyInfo[] propertys = model.GetType().GetProperties(); for (int i = 0; i < jsonArray.Count; i++) { T _model = (T)((ICloneable)model).Clone(); Newtonsoft.Json.JavaScriptObject Jobject = ((Newtonsoft.Json.JavaScriptObject)((Newtonsoft.Json.JavaScriptArray)jsonArray)[i]); for (int n = 0; n < Jobject.Count; n++) { for (int j = 0; j < propertys.Length; j++) { if (propertys[j].Name == "WorkId") { break; } if (Jobject.ToList()[n].Key.Trim().ToUpper() == propertys[j].Name.ToUpper()) { if (propertys[j].PropertyType.Equals(typeof(Int32))) { propertys[j].SetValue(_model, Convert.ToInt32(Jobject.ToList()[n].Value.ToString().Trim() == "" ? 0 : Jobject.ToList()[n].Value), null); } else if (propertys[j].PropertyType.Equals(typeof(Int64))) { propertys[j].SetValue(_model, Convert.ToInt64(Jobject.ToList()[n].Value.ToString().Trim() == "" ? 0 : Jobject.ToList()[n].Value), null); } else if (propertys[j].PropertyType.Equals(typeof(decimal))) { propertys[j].SetValue(_model, Convert.ToDecimal(Jobject.ToList()[n].Value.ToString().Trim() == "" ? 0 : Jobject.ToList()[n].Value), null); } else if (propertys[j].PropertyType.Equals(typeof(DateTime))) { propertys[j].SetValue(_model, Convert.ToDateTime(Jobject.ToList()[n].Value.ToString().Trim() == "" ? DateTime.Now.ToString() : Jobject.ToList()[n].Value), null); } else { propertys[j].SetValue(_model, Jobject.ToList()[n].Value.ToString(), null); } break; } } } list.Add(_model); } return(list); }
/// <summary> /// Initializes a new instance of the <see cref="JavaScriptObject"/> class that /// contains values copied from the specified <see cref="JavaScriptObject"/>. /// </summary> /// <param name="javaScriptObject">The <see cref="JavaScriptObject"/> whose elements are copied to the new object.</param> public JavaScriptObject(JavaScriptObject javaScriptObject) : base(javaScriptObject, EqualityComparer <string> .Default) { }