/// <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数组形式。

最新文章

  1. Iptables工作原理使用详解
  2. 让powershell同时只能运行一个脚本(进程互斥例子)
  3. 搞定迅雷固件在TP-LINK WR720N,127.0.0.1 9000 获取不到激活码
  4. 【20】宁以pass-by-reference-to-const替换pass-by-value
  5. Word 中标题的编号变成黑框
  6. python操作redis-事务
  7. Smallest multiple
  8. break、continue以及return的区别
  9. JWT 加密
  10. 使用iconfont图标
  11. 【第三篇】SAP ABAP7.5x新语法之程序结构&amp;SubScreen
  12. 小议 开源中国 I LOVE YOU js代码
  13. [转]极不和谐的 fork 多线程程序
  14. camera原理
  15. Arraylist静态初始化
  16. (转)I 帧和 IDR 帧的区别
  17. JSON.parse()和JSON.stringify()的使用
  18. 使用AllocConsole()添加调试用控制台
  19. smartJS 0.1 API 讲解 - PromiseEvent
  20. RPC电源监控总结

热门文章

  1. 栈(stack)--c实现(使用双链表)
  2. Swift编写的一些完整的app
  3. HDOJ 2828 Lamp DLX反复覆盖
  4. 【Android】把外部文件拷贝的AVD安卓模拟器上的sdcard上,而且在AVD中浏览sdcard的文件
  5. leetcode——Insertion Sort List 对链表进行插入排序(AC)
  6. RISC-V首度被我国列入扶持对象,上海已成RISC-V重要“据点”
  7. springboot actuator shutdown正确的关闭操作
  8. Andoid 更好的Android多线程下载框架
  9. vcenter server appliance 5.5 管理中心 linux 版本的部署
  10. 编译报错一列----aclocal找不到