zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    23)PHP,数组操作函数
    22)PHP,数组排序函数
    21)PHP,杨辉三角
    数据库三大范式
    SQL Server 中关于EXCEPT和INTERSECT的用法
    面试准备
    面试总结
    jQuery函数attr()和prop()的区别
    SVN checkout出某个特定版本
    SVN 中的忽略文件
  • 原文地址:https://www.cnblogs.com/xbblogs/p/4808535.html
Copyright © 2011-2022 走看看