在 C# 中使用 JavaScriptSerializer 序列化时出错
Getting error while serializing using JavaScriptSerializer in c#
当我在 wcf 服务中使用 JavaScriptSerializer 进行序列化时,它给出了定义代码的以下错误。
代码:
DataCollection<Entity> detailqueryentityCollection = _serviceProxy.RetrieveMultiple(detailquery).Entities;
if (detailqueryentityCollection.Count > 0)
{
listdata = new JavaScriptSerializer().Serialize(detailqueryentityCollection);
}
错误:
Error during serialization or deserialization using the JSON
JavaScriptSerializer. The length of the string exceeds the value set
on the maxJsonLength property.
我还在 web.config 中添加了以下代码,但它不起作用。
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="500000000"/>
</webServices>
</scripting>
</system.web.extensions>
请给我任何解决方案。
自己实例化class时,需要给class的MaxJsonLength
属性加上值:
var jss = new JavaScriptSerializer();
jss.MaxJsonLength = 500000000;
listData = jss.Serialize(detailqueryentityCollection);
当我在 wcf 服务中使用 JavaScriptSerializer 进行序列化时,它给出了定义代码的以下错误。
代码:
DataCollection<Entity> detailqueryentityCollection = _serviceProxy.RetrieveMultiple(detailquery).Entities;
if (detailqueryentityCollection.Count > 0)
{
listdata = new JavaScriptSerializer().Serialize(detailqueryentityCollection);
}
错误:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
我还在 web.config 中添加了以下代码,但它不起作用。
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="500000000"/>
</webServices>
</scripting>
</system.web.extensions>
请给我任何解决方案。
自己实例化class时,需要给class的MaxJsonLength
属性加上值:
var jss = new JavaScriptSerializer();
jss.MaxJsonLength = 500000000;
listData = jss.Serialize(detailqueryentityCollection);