【问题标题】:Error 'The length of the string exceeds the value set on the maxJsonLength property.'错误“字符串的长度超过了 maxJsonLength 属性上设置的值。”
【发布时间】:2020-07-31 15:48:02
【问题描述】:

我正在将图像数据从后端传递到前端。如果图像尺寸小,一切正常。否则我会收到以下错误:'使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了 maxJsonLength 属性设置的值。我研究了一些建议,但到目前为止还没有运气。

    public static ModelResponse GetData(int imageID, string docType)
    {
        var imageData = DataConnection.Test.GetData(fileID).FirstOrDefault();

        ImageFileDTO imageFile = new ImageFileDTO
        {
            ImageFileData = Convert.ToBase64String(imageData.FileData)
        };

        var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        serializer.MaxJsonLength = Int32.MaxValue;

        var result = serializer.Serialize(imageFile);
        return new ModelResponse(result);
    }

我还在网络配置中设置了 maxJsonLenght

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

【问题讨论】:

标签: javascript c#


【解决方案1】:
<jsonSerialization maxJsonLength="2147483644" />

试试这个。

【讨论】:

    猜你喜欢
    • 2015-04-06
    • 2013-05-26
    • 2015-03-27
    • 2012-08-06
    • 2015-05-30
    • 1970-01-01
    • 2018-04-25
    • 2017-08-31
    • 2013-10-07
    相关资源
    最近更新 更多