首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-09-04 
C#的Dictionary字典怎么序列化成JSON模式,以及如何调用下面是我获取的的一个Dictionary对象public Diction

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()

热点排行