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:不同的数据源, ...
随机推荐
- Sql Server中常用的6个自定义函数分享
转自:http://www.jb51.net/article/56691.htm IF OBJECT_ID('DBO.DISTINCT_STR') IS NOT NULL DROP FUNCTION ...
- [hdu 1568] Fibonacci数列前4位
2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2 ...
- Vue Study [2]: Vue Router
Description The article for vue router. Original post link:https://www.cnblogs.com/markjiang7m2/p/10 ...
- tinkphp中的自动验证
tinkphp是国内非常流行的一个开源框架,国内大小公司都在用的框架.对于初学的好多同学感觉不太好上手,其实并没没有大家想的那么复杂.自动验证功能是thinkphp提高的一种数据验证方法,分为动态和静 ...
- Python的安装位置与Python库
如何查看Python的安装位置: 输入 where python ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- day20 模块 collections time sys os
1.模块 1. 模块的定义:我们把装有特定功能的代码进行归类的结果.我们目前写的所有py文件都是模块 2. 引入模块的方式: 1.import 模块名 2.from xxx import 模块名 2. ...
- linux 远程装机
首先,服务器配置dhcp 关闭火墙yum install dhcp -ycd /etc/dhcpcp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ...
- web服务器Nginx环境下如何实现安全证书https的配置
https跟http的关系 https没出现之前,我们网站大多数都是http开头,http全名超文本传输协议,客户端据此获取服务器上的超文本内容.超文本内容则以HTML为主,客户端拿到HTML内容后可 ...
- angularJs(2)表单中下拉框单选多选
多选 <input type="checkbox" ng-model='game' ng-true-value="1" ng-false-value=&q ...
- 23-----BBS论坛
BBS论坛(二十三) 23.添加板块 (1)apps/models class BoardModel(db.Model): __tablename__ = 'board' id = db.Column ...