Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

c# - 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: enter image description here

Here is my script: enter image description here

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

question from:https://stackoverflow.com/questions/66068997/i-am-getting-a-the-length-of-the-string-exceeds-the-value-set-on-the-maxjsonlen

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...