码迷,mamicode.com
首页 > Web开发 > 详细

解决JSON字符长度超出限制

时间:2017-09-18 22:27:00      阅读:584      评论:0      收藏:0      [点我收藏+]

标签:div   bll   config   处理程序   manager   javascrip   pre   sre   back   

环境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 }

 

解决JSON字符长度超出限制

标签:div   bll   config   处理程序   manager   javascrip   pre   sre   back   

原文地址:http://www.cnblogs.com/Daniell/p/7544967.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!