JSON 可以容纳的数量是否有限制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1262376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a limit on how much JSON can hold?
提问by JasonDavis
I am using jquery, JSON, and AJAX for a comment system. I am curious, is there a size limit on what you can send through/store with JSON? Like if a user types a large amount and I send it through JSON is there some sort of maximum limit?
我将 jquery、JSON 和 AJAX 用于评论系统。我很好奇,您可以通过 JSON 发送/存储的内容是否有大小限制?就像如果用户键入大量内容并且我通过 JSON 发送它是否有某种最大限制?
Also can any kind of text be sent through JSON. for example sometime I allow users to use html, will this be ok?
也可以通过 JSON 发送任何类型的文本。例如,有时我允许用户使用 html,这样可以吗?
采纳答案by Amber
JSON is similar to other data formats like XML - if you need to transmit more data, you just send more data. There's no inherent size limitation to the JSON request. Any limitation would be set by the server parsing the request. (For instance, ASP.NET has the "MaxJsonLength" property of the serializer.)
JSON 类似于 XML 等其他数据格式 - 如果您需要传输更多数据,只需发送更多数据。JSON 请求没有固有的大小限制。解析请求的服务器将设置任何限制。(例如,ASP.NET 具有序列化程序的“MaxJsonLength”属性。)
回答by cdiggins
There is no fixed limit on how large a JSON data block is or any of the fields.
JSON 数据块或任何字段的大小没有固定限制。
There are limits to how much JSON the JavaScript implementation of various browsers can handle (e.g. around 40MB in my experience). See this question for example.
各种浏览器的 JavaScript 实现可以处理多少 JSON 是有限制的(例如,根据我的经验,大约 40MB)。例如,请参阅此问题。
回答by Anthony F
It depends on the implementation of your JSON writer/parser. Microsoft's DataContractJsonSerializer seems to have a hard limit around 8kb (8192 I think), and it will error out for larger strings.
这取决于您的 JSON 编写器/解析器的实现。微软的 DataContractJsonSerializer 似乎有一个大约 8kb(我认为是 8192)的硬限制,并且它会为更大的字符串出错。
Edit: We were able to resolve the 8K limit for JSON strings by setting the MaxJsonLength property in the web config as described in this answer: https://stackoverflow.com/a/1151993/61569
编辑:我们能够通过在网络配置中设置 MaxJsonLength 属性来解决 JSON 字符串的 8K 限制,如本答案所述:https://stackoverflow.com/a/1151993/61569
回答by Chaitanya Belsare
There is really no limit on the size of JSON data to be send or receive. We can send Json data in file too. According to the capabilities of browser that you are working with, Json data can be handled.
要发送或接收的 JSON 数据的大小实际上没有限制。我们也可以在文件中发送 Json 数据。根据您使用的浏览器的功能,可以处理 Json 数据。
回答by stleary
Implementations are free to set limits on JSON documents, including the size, so choose your parser wisely. See RFC 7159, Section 9. Parsers:
实现可以自由地对 JSON 文档设置限制,包括大小,因此请明智地选择您的解析器。请参阅RFC 7159,第 9 节。解析器:
"An implementation may set limits on the size of texts that it accepts. An implementation may set limits on the maximum depth of nesting. An implementation may set limits on the range and precision of numbers. An implementation may set limits on the length and character contents of strings."
“一个实现可以对它接受的文本大小设置限制。一个实现可以对嵌套的最大深度设置限制。一个实现可以对数字的范围和精度设置限制。一个实现可以对长度和字符设置限制字符串的内容。”
回答by mathias.horn
If you are working with ASP.NET MVC, you can solve the problem by adding the MaxJsonLengthto your result:
如果您正在使用 ASP.NET MVC,则可以通过将MaxJsonLength添加到结果中来解决问题:
var jsonResult = Json(new
{
draw = param.Draw,
recordsTotal = count,
recordsFiltered = count,
data = result
}, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
回答by Perfect64
Surely everyone's missed a trick here. The current file size limit of a json file is 18,446,744,073,709,551,616 characters or if you prefer bytes, or even 2^64 bytes if you're looking at 64 bit infrastructures at least.
当然,每个人都在这里错过了一个技巧。json 文件的当前文件大小限制为 18,446,744,073,709,551,616 个字符,或者如果您更喜欢字节,或者如果您至少查看 64 位基础架构,则甚至是 2^64 字节。
For all intents, and purposes we can assume it's unlimited as you'll probably have a hard time hitting this issue...
出于所有意图和目的,我们可以假设它是无限的,因为您可能很难解决这个问题......
回答by Shashi Keshar
The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data.
JSON 字符串的最大长度。默认为 2097152 个字符,相当于 4 MB 的 Unicode 字符串数据。
Refer below URL
参考以下网址

