把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

最新文章

  1. android使用PullToRefresh实现上拉加载和下拉刷新效果
  2. PHP 之 CURL 模拟登陆并获取数据
  3. Android 取源码时 error: could not verify the tag &#39;v1.12.4&#39;的解决
  4. HtmlAgilityPack 删除script、style以及注释标签
  5. 01 Node.js简介, 安装&amp;配置
  6. c# 并行运算
  7. MySQL半同步复制的安装和配置
  8. HQL查询语言的使用介绍
  9. spring 自定义schema
  10. python,redis简单订阅
  11. sql-yog
  12. 云信推送通知 APN invalid Token
  13. Android开发学习之路--Android系统架构初探
  14. 微信二维码支付-模式一(PC端,解决中文乱码问题)
  15. python 字典 dict 该注意的一些操作
  16. ELK日志监控平台安装部署简介--Elasticsearch安装部署
  17. Field笔记
  18. Nand Flash 驱动框架
  19. phpunit 生成三种日志文件的配置方法
  20. Python之tornado

热门文章

  1. Java性能优化之高性能JAVA代码的若干个习惯
  2. oracle select非group by的字段
  3. linux下redis的安装与django-redis使用方法
  4. 智能合约安全事故回顾(3)-DOS漏洞导致的KotET事件
  5. 最长双回文串——manacehr
  6. (Python OpenGL)【5】平移 PyOpenGL
  7. socket中close发生的事情,RST,pipe信号错误
  8. 关于AppiumDriver
  9. 异步解决方案(三)Promise
  10. Tomcat分析-启动过程