简体   繁体   中英

I am getting a “The length of the string exceeds the value set on the maxJsonLength property”

I am attempting to pass a json object in the data: JSON.stringify(dataObj) of a ajax call and I am never getting to the ajax destination of my MVC Controller. It works perfectly with smaller sized versions of the object. This only occurs when passing to the controller vs. returning from in which I do this: 在此处输入图像描述

Here is my script: 在此处输入图像描述

Need a little guidance here. Nothing seems to fix this.

You are hitting the max size of your json payload so your serializer is throwing an exception. This doesn't have anything to do with your JavaScript, it's all in your backend.

You need to set the MaxJsonLength property on your JavaScriptSerializer settings

The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data.

Example: serializer.MaxJsonLength = <something big enough to support your payload> ;

If that still doesn't work, update your web.config with something similar:

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration>

It may also help to determine how big your payload actually is before returning it.

https://docs.microsoft.com/en-us/dotnet/api/system.web.script.serialization.javascriptserializer.maxjsonlength?view=netframework-4.8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM