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
ToDictionary写法的更多相关文章
- 字符串按首字母分组并ToDictionary的实现
这是一道面试题目,要求实现字符串按首字母分组并ToDictionary输出,当时没有做出来,后面研究了一下,现在将这道题的几种实现方式记录下来. 首先初始化数据源,是一个List<string& ...
- c#高级写法
Linq的参考资料:https://www.cnblogs.com/liqingwen/p/5801249.html 1.判断str字符串中的逗号个数 string str = "1,2,3 ...
- obj.style.z-index的正确写法
obj.style.z-index的正确写法 今天发现obj.style.z-index在js里面报错,后来才知道在js里应该把含"-"的字符写成驼峰式,例如obj.style.z ...
- java设计模式之单例模式(几种写法及比较)
概念: Java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例.饿汉式单例.登记式单例. 单例模式有以下特点: 1.单例类只能有一个实例. 2.单例类必须自己创建 ...
- .NET跨平台之旅:数据库连接字符串写法引发的问题
最近在一个ASP.NET Core站点中遇到一个奇怪问题.当用dotnet run命令启动站点后,开始的一段时间请求执行速度超慢,有时要超过20秒,有时甚至超过1分钟,日志中会记录这样的错误: Sys ...
- 【兼容写法】HttpServerUtility.Execute 在等待异步操作完成时被阻止。关键词:MVC,分部视图,异步
异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html MVC6之前的版本,对分部视图的异步支持不是很好 问题: 视图里面有分布视图:@{ ...
- 常用原生JS方法总结(兼容性写法)
经常会用到原生JS来写前端...但是原生JS的一些方法在适应各个浏览器的时候写法有的也不怎么一样的... 今天下班有点累... 就来总结一下简单的东西吧…… 备注:一下的方法都是包裹在一个EventU ...
- touchstart,touchmove,touchend事件 写法
jQuery写法: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var ...
- 前端导出Excel兼容写法
今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...
随机推荐
- Kotlin第一篇 Hello Kotlin以及简单介绍。
首先需要一个编译器,我们使用Intellij IDE https://www.jetbrains.com/idea/download/#section=windows 下载下来安装好. 那么我们就来 ...
- jdk 1.6.0_39 下载
Java SE Development Kit 6u39 Product / File Description File Size Download password Linux x86 65.42 ...
- Laplace(拉普拉斯)算子
[摘要] Laplace算子作为边缘检测之一,和Sobel算子一样也是工程数学中常用的一种积分变换,属于空间锐化滤波操作.拉普拉斯算子(Laplace Operator)是n维欧几里德空间中的一个二阶 ...
- CF581D Three Logos 暴力
Three companies decided to order a billboard with pictures of their logos. A billboard is a big squa ...
- 洛谷 P1036 选数
嗯.... 这种类型的题在新手村出现还是比较正常的, 但是不知道为什么它的分类竟然是过程函数与递归!!!(难道这不是一个深搜题吗??? 好吧这就是一道深搜题,所以千万别被误导... 先看一下题目: 题 ...
- spring-redis 存储数据
package com.fndsoft.bcis.utils; import org.springframework.beans.factory.annotation.Autowired;import ...
- echarts图调用多个接口
html: <div id="sentimentMain1" style="width:960px;height:500px;margin:20px auto;&q ...
- git命令行操作:拉不到最新代码???
现场场景: 仓库中有一个包名使用了驼峰命名,还有一个非驼峰的同名包, windows系统下因为不区分文件夹大小写,拉取没问题,但是本地push不上去.打算到Linux上clone下来后,删除那个驼 ...
- Storm(1)-centos7下安装单机版Strom
1.所需软件: jdk8.zookeeper.storm 2.安装zookeeper单机版 下载:http://zookeeper.apache.org/releases.html#download ...
- my.宝石 --- --- ZC 收集
1. DT PT 头盔 太阳石 物理伤害+8 √ 月亮石 物理防御+12 √ 武器 太阳石 物理伤害+8 √ 舍利子 法术伤害+6 ...