把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

ToDictionary写法的更多相关文章

  1. 字符串按首字母分组并ToDictionary的实现

    这是一道面试题目,要求实现字符串按首字母分组并ToDictionary输出,当时没有做出来,后面研究了一下,现在将这道题的几种实现方式记录下来. 首先初始化数据源,是一个List<string& ...

  2. c#高级写法

    Linq的参考资料:https://www.cnblogs.com/liqingwen/p/5801249.html 1.判断str字符串中的逗号个数 string str = "1,2,3 ...

  3. obj.style.z-index的正确写法

    obj.style.z-index的正确写法 今天发现obj.style.z-index在js里面报错,后来才知道在js里应该把含"-"的字符写成驼峰式,例如obj.style.z ...

  4. java设计模式之单例模式(几种写法及比较)

    概念: Java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例.饿汉式单例.登记式单例. 单例模式有以下特点: 1.单例类只能有一个实例. 2.单例类必须自己创建 ...

  5. .NET跨平台之旅:数据库连接字符串写法引发的问题

    最近在一个ASP.NET Core站点中遇到一个奇怪问题.当用dotnet run命令启动站点后,开始的一段时间请求执行速度超慢,有时要超过20秒,有时甚至超过1分钟,日志中会记录这样的错误: Sys ...

  6. 【兼容写法】HttpServerUtility.Execute 在等待异步操作完成时被阻止。关键词:MVC,分部视图,异步

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html MVC6之前的版本,对分部视图的异步支持不是很好 问题: 视图里面有分布视图:@{ ...

  7. 常用原生JS方法总结(兼容性写法)

    经常会用到原生JS来写前端...但是原生JS的一些方法在适应各个浏览器的时候写法有的也不怎么一样的... 今天下班有点累... 就来总结一下简单的东西吧…… 备注:一下的方法都是包裹在一个EventU ...

  8. touchstart,touchmove,touchend事件 写法

    jQuery写法: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var ...

  9. 前端导出Excel兼容写法

    今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...

随机推荐

  1. c# 大文件分割 复制 Filestream 进度条

    大文件分割复制,每次复制100M 也可以复制别的较大数值. 小于1G的小文件就直接复制得了.代码里没写 ,但是很简单 直接写进去就好了,难得是分割复制 所以没写. 好吧 我还是改了 改成小文件也可以复 ...

  2. pg10.1 orafce3.6 安装

    安装unzip orafce-mastermv orafce-master /opt/soft_bak/postgresql-10.1/contribcd /opt/soft_bak/postgres ...

  3. 并查集【洛谷P1197】 [JSOI2008]星球大战

    P1197 [JSOI2008]星球大战 题目描述 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治着整个星系. 某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系 ...

  4. atcoder 2643 切比雪夫最小生成树

    There are N towns on a plane. The i-th town is located at the coordinates (xi,yi). There may be more ...

  5. Codeforces Round #503 (by SIS, Div. 2)B 1020B Badge (拓扑)

    题目大意:每个同学可以指定一个人,然后构成一个有向图.1-n次查询,从某个人开始并放入一个东西,然后循环,直到碰到一个人已经放过了,就输出. 思路:直接模拟就可以了,O(n^2) 但是O(n)也可以实 ...

  6. PHP删除目录下的空目录

    function rm_empty_dir($path){       if(is_dir($path) && ($handle = opendir($path))!==false){ ...

  7. 面试题 和 python 2与3的期区别

      1.3 python2与python3的一些区别 大环境下的区别:python2:1,源码都含有php,Java,C,等语言的规范陋习,2,重复代码特别多. python3:源码很规范,清晰,简单 ...

  8. Python迭代器生成器,模块和包

      1.迭代器和生成器 2.模块和包 1.迭代器 迭代器对象要求支持迭代器协议的对象,在Python中,支持迭代器协议就是实现对象的__iter__()和__next__()方法.    其中__it ...

  9. rhcs红帽插件及 轮循

    server1:yum install luci ricci -yecho westos | passwd -stdin  ricci/etc/init.d/ricci startchkconfig ...

  10. Linux下如何使用Wireshark进行抓包

    1. 安装wireshark Ubuntu 14.04.3 缺省安装后, 不包含Wireshark抓包软件,因此首先需要手工进行Wireshark的安装:     apt-get update apt ...