在c#中使用JavaScriptSerializer进行序列化时得到错误
问题描述:
当我在wcf服务中使用JavaScriptSerializer进行序列化时,它给出了定义代码的以下错误。在c#中使用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>
请给我建议任何解决方案。
答
当自己实例化类,你需要将值添加到类的MaxJsonLength
属性:
var jss = new JavaScriptSerializer();
jss.MaxJsonLength = 500000000;
listData = jss.Serialize(detailqueryentityCollection);
嗨威尔·雷,Thanx.Which你的建议和web.config中的变化同时需要改变?或者你给我足够了? –
@chhaya_patel对于你的用例,你不需要配置文件部分。 –
嗨感谢您的帮助。 –