版权声明:以上纯属个人独自研究成果,仅供参考,转载请注明出处 https://blog.csdn.net/u012847695/article/details/50857805
返回从后台JSON到前台的时候蹦出的错:
The length of the string exceeds the value set on the maxJsonLength propert
网上的解决办法都是说在web.config里加段:
但是没起作用
我的解决办法是:
网上的解决办法都是说在web.config里加段:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
但是没起作用
我的解决办法是:
public ActionResult Get(DateTime dateFrom, DateTime dateTo)
{
DataTable list = GetList(dateFrom, dateTo);
var salegoodsList = list.AsEnumerable().GroupBy(t => t["Dimension0"]).Select(n =>
new
{
goodsid = n.Key,
qty = n.Sum(s => s["销售数量"] == "" ? 0 : Convert.ToInt32(s["销售数量"])),
stock = n.Sum(s => s["库存"] == "" ? 0 : Convert.ToInt32(s["库存"]))
});
//关键代码,可设置JSON的长度
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
var retobject = new
{ salegoodsList = salegoodsList ,
dateFrom = dateFrom
};
var result = new ContentResult();
result.Content = serializer.Serialize(retobject);
result.ContentType = "application/json";
return result;
}