【发布时间】:2018-09-11 11:52:28
【问题描述】:
我在 .cshtml 文件中使用以下代码。
var typeVM = JSON.parse('@Html.Raw(Json.Encode(Model.typeVM))');
显示以下错误:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
我无法为Json Encode 函数定义最大长度,并且Web.config 配置仅适用于web-services。
那么问题是这个问题的可能解决方案是什么?
如何定义jsonMaxLength 属性?
【问题讨论】:
-
首先,它应该是
var typeVM = @Html.Raw(Json.Encode(Model.typeVM))(将您的 json 转换为字符串然后再将其转换回来毫无意义)。要问自己的真正问题是,为什么首先要向视图发送这么多数据 -
重点是我在直接将字符串转换为 json 对象时遇到了转义序列问题。
标签: c# json asp.net-mvc asp.net-mvc-4 jsonserializer