下面是asp.net mvc后台代码 return一个序列化Dictionary<int,model>

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Dictionary<int, Model.GameCategoryOne> dic = new Dictionary<int, Model.GameCategoryOne>();

Model.GameCategoryOne model = new Model.GameCategoryOne
{
  CategoryId = BLL.GameVocabulary.GetCount("CategoryOneValue = 0 "),
  CategoryName = "未分类的词汇集"
};

dic.Add(0, model);

return Json(dic, JsonRequestBehavior.AllowGet);

 

在前端用jq请求 然后接收 控制台输出 却报错 500 服务器错误

$.getJSON("url", null, function (data) {
 console.log(data);
})

然后各种后端调试 return 的序列化json也是没问题 都能return 然后前端就是报500错 

本人对前端不怎么熟悉 实在没办法 请人帮忙调试了一下 前端浏览器调试

是因为Json不支持int类型的key  把Dictionary<int,model>  改为Dictionary<string,model>就解决了

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄