ToDictionary写法

把List集合转化成Dictionary

  public ActionResult Dimo()
  { 
    Dictionary<string, Object> param = new Dictionary<string, Object>();
     param.Add("UID", user.UID);
    string urlUserPoints = RouteManager.GetApiRoute("User", "GetPointById", param);
    List<UserPoints> userPoints = JsonConvert.DeserializeObject<UserPoints>(UserList.GetUser(urlUserPoints));

    string urlGetIndustriesAndJobs = RouteManager.GetApiRoute("User", "GetIndustriesAndJobs");
    Dictionary<string, Object> param2 = JsonConvert.DeserializeObject<Dictionary<string, Object>>(UserList.GetUser(urlGetIndustriesAndJobs));
    List<CatalogForIndustries> catalogForIndustries = SerializeHelper.DeserializeFromJson<List<CatalogForIndustries>>(SerializeHelper.SerializeToJson(param2["catalogForIndustries"]));
    //与第一个不同,第二个传来的是一个Dictionary,这个字典中包含两个集合,所以在反序列化后并无法直接转化成list集合,所以需要再序列化反序列化一次
    Dictionary<string, List<CatalogForIndustries>> temp = catalogForIndustries.GroupBy(a => a.ParentID).ToDictionary(a => a.Key, a => a.ToList());   
    //这个是ToDictionary的写法,把list转化成Dictionary 字典 
     this.ViewBag.catalogGroup = temp;
    return view();
  } [HttpGet] [SecurityCheck]
public HttpResponseMessage GetIndustriesAndJobs(string guid) { List<CatalogForIndustries> industies = BllFactory.Instance.UserBLL.GetCatalogForIndustries(); List<CatalogForJobs> jobs = BllFactory.Instance.UserBLL.GetCatalogForJobs(); Dictionary<string,object> param = new Dictionary<string,object>(); param.Add("catalogForIndustries", industies); param.Add("catalogForJobs", jobs); return ConvertHelper.toJson(param); }

 

 以上是个人经验和理解(有点生涩),写给自己看的,看得懂就用,看不懂不要pen

转载于:https://www.cnblogs.com/xbblogs/p/4808535.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值