混乱超过maxJsonLength默认值 [英] Confusion over maxJsonLength default value

查看:277
本文介绍了混乱超过maxJsonLength默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望得到一些关于maxJsonLength属性的澄清。这是一些背景信息。

I'm hoping to get some clarification on the maxJsonLength property. Here is some background information.

我在使用jQuery的.NET Web应用程序中没有返回AJAX响应的问题。当用户更改下拉列表时,我手动构建并显示了一些HTML。问题是一个特定的选择返回一个大约140kB的字符串,但它不会显示在浏览器中。我把问题缩小到字符串的长度太长。在搜索SO和其他地方时,我发现问题可以通过手动设置maxJsonLength 的值来解决我的web.config。

I was having an issue with an AJAX response not being returned in a .NET web application using jQuery. When the user changed a drop down list, I manually built and displayed some HTML. The issue was that one specific selection returned a string that was about 140kB but it would not display in the browser. I narrowed the problem down to the length of the string being too long. In searching SO and elsewhere, I found that the issue could be resolved by manually setting the value of maxJsonLength in my web.config.

我的困惑是关于th maxJsonLength属性的默认值。有些答案说它是2097152个字符和参考资料此MSDN链接。但其他人说默认长度为102400,并参考此其他MSDN链接。在我的测试中,我得出的结论是默认值为102400字节,但我不确定其他默认值的原因。

My confusion is about the default value of th maxJsonLength property. Some answers say it's 2097152 characters and reference this MSDN link. But others have said the default length is 102400 and reference this other MSDN link. In my testing, I've come to the conclusion that the default is 102400 bytes but I'm not sure of the reason for the other default value.

推荐答案

在网站上创建页面,代码中包含以下代码:

Creating a page on a website with the following in the code behind:

JavaScriptSerializer serializer = new JavaScriptSerializer();

Response.Write("Max Length: " + serializer.MaxJsonLength);

指向输出:


最大长度:2097152

Max Length: 2097152

所以我会使用 docs 而不是如何。

So I would go with the value defined in the docs rather than the How to.

请注意,这是字符,而不是字节显式:

Note however that this is Characters, and not bytes explicitly:


默认值为2097152字符,相当于4 MB的Unicode字符串数据

The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data

这篇关于混乱超过maxJsonLength默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆