下面是memcached 中获取的obj 类型的数据,转list
string sessionId = Request.Cookies["sessionId"].Value;//授权从Cookie中传递过来的Memcache的Key Object obj = MemcachedHelper.Get(sessionId);//根据key从Memcache中获取用户的信息 // 序列化为JSON字串 string _json = JsonConvert.SerializeObject(obj); List<UsersJsonParam> userInfo = new List<UsersJsonParam>(); // 反序列化 userInfo = JsonConvert.DeserializeObject<List<UsersJsonParam>>(obj.ToString());
不知为何
ICollection,IEnumerable 转换不行
ICollection<object> list1 = obj as ICollection<object>; IEnumerable<object> list2 = obj as IEnumerable<object>;
obj 转 IEnumerable
/// <summary> /// 这是子页面 /// </summary> /// <returns></returns> public ActionResult Edit() { //----查询 分组 数据列表 开始---- int Page = Convert.ToInt32(string.IsNullOrWhiteSpace(Request["page"]) ? "1" : Request["page"]); int limit = Convert.ToInt32(string.IsNullOrWhiteSpace(Request["limit"]) ? "100" : Request["limit"]); Group Group = new Group(); Group.GroupId = Convert.ToInt32(string.IsNullOrWhiteSpace(Request["GroupId"]) ? "0" : Request["GroupId"]); Group.GroupCode = string.IsNullOrWhiteSpace(Request["GroupCode"]) ? "" : Request["GroupCode"]; Group.GroupName = string.IsNullOrWhiteSpace(Request["GroupName"]) ? "" : Request["GroupName"]; JsonResultDapper jrd = GroupManager.SelectGroupList(Group, Page, limit); //----查询 分组 数据列表 结束---- var selectItemList = new List<SelectListItem>() { new SelectListItem(){ Value="0", Text="--全部--", Selected=true } }; IEnumerable<object> list = jrd.rows as IEnumerable<object>; var GroupList = new SelectList(list, "GroupId", "GroupName"); selectItemList.AddRange(GroupList); ViewBag.database = selectItemList; return PartialView(); }