环境asp.net 4.0 ,AJAX 一般处理程序
碰到JSON字符长度超出限制,抛出异常,参考了网上资料和网友博客
web.config添加以下内容
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="20971520"/>
</webServices>
</scripting>
</system.web.extensions>
ashx业务文件中添加红色代码就OK
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Configuration; 6 using System.Web.Script.Serialization; 7 using MODEL; 8 using TOOL; 9 using BLL;10 using System.Web.Configuration;11 namespace UI.ajax.stock12 {13 ????/// <summary>14 ????/// stockin 的摘要说明15 ????/// </summary>16 ????public class stockin : IHttpHandler17 ????{18 19 ????????public void ProcessRequest(HttpContext context)20 ????????{21 ????????????context.Response.ContentType = "text/plain";22 ????????????stockInBLL bll = new stockInBLL();23 ????????????List<MODEL.stockin> list = bll.getStockIn();24 ????????????//序列化25 ????????????JavaScriptSerializer jss = new JavaScriptSerializer();26 ?????????????ScriptingJsonSerializationSection section = ConfigurationManager.GetSection("system.web.extensions/scripting/webServices/jsonSerialization") as ScriptingJsonSerializationSection;27 ??????????28 ????????????????if (section != null)29 ????????????????{30 ????????????????????jss.MaxJsonLength = section.MaxJsonLength;31 ????????????????????jss.RecursionLimit = section.RecursionLimit;32 ????????????????}33 ????????????context.Response.Write(jss.Serialize(list));34 ????????}35 36 ????????public bool IsReusable37 ????????{38 ????????????get39 ????????????{40 ????????????????return false;41 ????????????}42 ????????}43 ????}44 }
解决JSON字符长度超出限制
原文地址:http://www.cnblogs.com/Daniell/p/7544967.html