【发布时间】:2013-04-11 03:47:25
【问题描述】:
这段代码的结果格式有问题
public JsonResult getCategorias(int? id)
{
var res = from c in db.Categorias
where (( id.HasValue && c.CategoriaPadre == id.Value) || (!id.HasValue && c.CategoriaPadre == null))
select new { id = c.Id, label = c.Descripcion };
return this.Json(res, JsonRequestBehavior.AllowGet);
}
这会返回一个json:
[{"id":21,"label":"Marketing3"},{"id":22,"label":"Marketing4"}]
但我需要这种格式的json:
{"21":"Marketing3","22":"Marketing4"}
我能做什么?
非常感谢,对不起我的英语。
【问题讨论】:
-
你想把你的列表转换成哈希吗?
-
嗨,戴夫...是的,就是这样
标签: asp.net-mvc json jsonresult