繁体   English   中英

错误“字符串的长度超过了 maxJsonLength 属性上设置的值。”

[英]Error 'The length of the string exceeds the value set on the maxJsonLength property.'

我正在将图像数据从后端传递到前端。 如果图像尺寸小,一切正常。 否则我会收到以下错误:“使用 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);
    }

我还在 web 配置中设置了 maxJsonLenght

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

尝试这个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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