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