解决JSON字符长度超出限制

环境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.stock
12 {
13     /// <summary>
14     /// stockin 的摘要说明
15     /// </summary>
16     public class stockin : IHttpHandler
17     {
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 IsReusable
37         {
38             get
39             {
40                 return false;
41             }
42         }
43     }
44 }

 

转载于:https://www.cnblogs.com/Daniell/p/7544967.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值