javascript - 错误“字符串的长度超过了 maxJsonLength 属性上设置的值。”
问题描述
我正在将图像数据从后端传递到前端。如果图像尺寸小,一切正常。否则我会收到以下错误:'使用 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>
解决方案
<jsonSerialization maxJsonLength="2147483644" />
尝试这个。
推荐阅读
- scala - 无形:找不到 Coproduct 映射的隐式
- javascript - 使用 Promise 通过 submit() 提交表单
- python - 从字符串中提取坐标
- lua - 如何向 Torch7 张量添加切片?
- java - 带有记忆的递归斐波那契的空间复杂度?
- spring-batch - 如何包含 Spring Batch JdbcBatchItemWriter 的计数器
- ubuntu - ubuntu 18 - 鼠标右键单击
- python-3.x - Tkinter 最佳按钮文字翻转方法
- arcore - ARCore 应用程序构建中的灰线而不是相机馈送
- sql - SQL Server:触发器错误