/// <summary>
/// 获取用户市信息
/// </summary>
/// <param name="CustomerId"></param>
/// <returns></returns>
[HttpPost]
public ActionResult GetCustomerProvinceAndCity(int CustomerId)
{
// 检测是否已有记录
IList<GenericAttribute> customerAttributes = _genericAttributeService.GetAttributesForEntity(CustomerId, "Customer");
Dictionary<string, string> myDictionary = new Dictionary<string, string>();
foreach (GenericAttribute item in customerAttributes)
{
//if (item.Key == "ProvinceName")
//{
// myDictionary["ProvinceName"] = item.Value;
// continue;
//} //if (item.Key == "CityName")
//{
// myDictionary["CityName"] = item.Value;
// continue;
//} if (item.Key == "ProvinceName")
{
myDictionary.Add("ProvinceName", item.Value);
continue;
} if (item.Key == "CityName")
{
myDictionary.Add("CityName", item.Value);
continue;
}
} if (myDictionary.Count > 0)
{ // 存在
return Json(new { result = true, info = myDictionary.ToArray(), msg = "获取成功" });
}
else
{ // 不存在
return Json(new { result = true, info = myDictionary.ToArray(), msg = "不存在" });
}
}

Dictionary 方便存储 key/value这种类型的数据,这个比Array要灵活一些。

上面的两种方式都可以保存数据。

判断数据数量,是通过Count属性。

最后返回数据的时候,可以统一转化为Array数组形式。

.Net中字典的使用的更多相关文章

  1. OC中如何把数组中字典的数据转换成URL?

    在使用objective-c语言开发iOS应用中,会向服务器通过URL请求一些数据,因此对URL的拼接肯定少不了.而在iOS中,我们一般是通过将字典中的数据拼接成我们要请求的URL字符串,那这个是怎么 ...

  2. Python中字典和集合

    Python中字典和集合 映射类型: 表示一个任意对象的集合,且可以通过另一个几乎是任意键值的集合进行索引 与序列不同,映射是无序的,通过键进行索引 任何不可变对象都可用作字典的键,如字符串.数字.元 ...

  3. Python对列表中字典元素排序

    问题起源 json对象a,b a = '{"ROAD": [{"id": 123}, {"name": "no1"}]} ...

  4. Django中字典在html中的遍历

    Django中字典在html中的遍历 如:在view中定义的函数 info = {'} context = {"info": info} 要在html中变量出info的信息(注意i ...

  5. python中字典的循环遍历的两种方式

    开发中经常会用到对于字典.列表等数据的循环遍历,但是python中对于字典的遍历对于很多初学者来讲非常陌生,今天就来讲一下python中字典的循环遍历的两种方式. 注意: python2和python ...

  6. python中字典排序,列表中的字典排序

    python中字典排序,列表中的字典排序 一.使用python模块:operator import operator #首先要导入模块operator x = {1:2, 3:4, 4:3, 2:1, ...

  7. python中字典的陷阱

    把字典与列表组合,如 i=20 s=[]#定义一个空列表 b={'d':i}#定义一个字典 while i>0: i=i-1 b['d']=i#更新字典的值 s.append(b) print( ...

  8. shell中字典的一个用法示例

    1. shell中字典的用法示例, 数组用法同字典 2. 以上使用sell配合字典实现的功能, 使用awk能轻松搞定, 如下: awk '{print $2}' file.txt | sort | u ...

  9. Python2 中字典实现的分析【翻译】

    在这片文章中会介绍 Python2 中字典的实现,Hash 冲突的解决方法以及在 C 语言中 Python 字典的具体结构,并分析了数据插入和删除的过程.翻译自python-dictionary-im ...

  10. [转帖]C#中字典集合HashTable、Dictionary、ConcurrentDictionary三者区别

    C#中字典集合HashTable.Dictionary.ConcurrentDictionary三者区别 https://blog.csdn.net/yinghuolsx/article/detail ...

随机推荐

  1. docker私有仓库yum安装 docker-registry

    [root@riyimei-node1:/root]> yum install docker-registryLoaded plugins: fastestmirror, langpacksLo ...

  2. vue单文件中引用路径的处理

    原文地址:vue单文件中引用路径的处理如有错误,欢迎指正! vue单文件的开发过程中,在单文件模版中可能会涉及到文件路径的处理,比如 <img>, style 中的 background ...

  3. 平凡主丛上的Yang-Mills理论

    本文是复旦大学由丁青教授的暑期课程“Yang-Mills理论的几何及其应用”所作笔记,会有少许修正. 所需基础: 多元微积分学 微分方程(常微分方程,数学物理方程) 曲线曲面论(初等微分几何) 以下是 ...

  4. Obfuscating computer code to prevent an attack

    A method and system for obfuscating computer code of a program to protect it from the adverse effect ...

  5. Qt之pro配置多个子工程/子模块

    简述 进行Qt项目开发的时候,尤其是大型项目,经常涉及多工程/多模块问题,其主要思想还是模块化,目的是为了降低程序复杂度,使程序设计.调试和维护等操作简单化. 简述 配置 效果 多工程 多模块 更多参 ...

  6. [Angular] Configure an Angular App at Runtime

    It always again happens (especially in real world scenarios) that you need to configure your Angular ...

  7. oracle树操作(select .. start with .. connect by .. prior)

    oracle中的递归查询能够使用:select .. start with .. connect by .. prior 以下将会讲述oracle中树形查询的经常使用方式.仅仅涉及到一张表. star ...

  8. jquery-easyui的datagrid在checkbox多选时,行选中不正确应,去除高亮的解决方法

    jquery-easyui的datagrid在checkbox多选时,行选中不正确应,去除高亮的解决方法 工作中用到一个具有多选功能的easyui-datagrid在处理cell的点击事件时,不同 ...

  9. iOS RegexKitLite 提取匹配的内容

            使用RegexKitLite正则表达式需要以下工作: 1.RegexKitLite官方网址(内含使用教程):http://regexkit.sourceforge.net/RegexK ...

  10. C#篇(三)——函数传参之引用类型和值类型

    首先应该认清楚在C#中只有两种类型: 1.引用类型(任何称为"类"的类型) 2.值类型(结构或枚举) 先来认识一下引用类型和值类型的区别: 函数传参之引用类型: 1.先来一个简单的 ...