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

查看:472
本文介绍了混乱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.

我的困惑是关于日maxJsonLength属性的默认值。一些答案,说这是2097152字符和引用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.maxjsonlength.aspx\"相对=nofollow>这个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.

推荐答案

在后面的code以下网站上创建的页面:

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

所以,我会去的<一个定义的值href=\"http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.maxjsonlength.aspx\"相对=nofollow>文档而不是如何。

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的Uni code字符串数据

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

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

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