当前位置: 代码迷 >> ASP.NET >> C#的Dictionary字典如何序列化成JSON模式,以及怎么调用
  详细解决方案

C#的Dictionary字典如何序列化成JSON模式,以及怎么调用

热度:7635   发布时间:2013-02-25 00:00:00.0
C#的Dictionary字典怎么序列化成JSON模式,以及如何调用
下面是我获取的的一个Dictionary对象
 public Dictionary<int, dynamic> GetCatalogTree() {
  Dictionary<int, dynamic> dic = new Dictionary<int, dynamic>();
  foreach (CatalogEntity catalog in CatalogViewModel.GetCatalogs()) {
  dynamic d = new ExpandoObject();
  d.title = catalog.Title;
  List<KeyValuePair<int,string>> list=new List<KeyValuePair<int,string>>();
  this.CatalogId=catalog.CatalogId;
  foreach (Catalog subCatalog in GetSubCatalogList()) {
  KeyValuePair<int, string> kvp = new KeyValuePair<int, string(subCatalog.CatalogId,subCatalog.Title);
  list.Add(kvp);
  }
  d.list = list;
  dic.Add(catalog.CatalogId, d);
  }
  return dic;
}
这里面的字典K是一个int类型,V是一个动态类型dynamic,dynamic里面的属性有一个string title和一个List集合,
list集合里面存的是一个KVP的数据类型


问题如题

------解决方案--------------------------------------------------------
字典也是可以的,和集合一样
------解决方案--------------------------------------------------------
将他转成LIST就可以了 dic.ToList()
  相关解决方案