字符串的长度超过了在maxJsonLength属性上设置的值.c# [英] The length of the string exceeds the value set on the maxJsonLength property.c#

查看:399
本文介绍了字符串的长度超过了在maxJsonLength属性上设置的值.c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从json中的wcf服务获取结果,如您所见:

I am trying to get the result from my wcf service in json as you can see :

public List<InquiryStatus> SearchInquiryStatus(string userid, string datestart, string dateend)
{
    string result = "";
    using (WebClient ClientRequest = new WebClient())
    {
        ClientRequest.Headers["Content-type"] = "application/json";
        ClientRequest.Encoding = System.Text.Encoding.UTF8;
        result = ClientRequest.DownloadString(ServiceHostName + "/MonitoringInquiryService.svc/SearchInquiryStatus/" +
                                                userid + "/" 
                                                + datestart + "/" + dateend
                                                );
    }
    var javascriptserializer = new JavaScriptSerializer();
    return javascriptserializer.Deserialize<List<InquiryStatus>>(result);
}

但是我得到这个错误:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Parameter name: input

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Parameter name: input

请注意,当我呼叫服务网址http://reporting.demo.ir/MonitoringInquiryService.svc/SearchInquiryStatus/null/'20171106'/'20171113'时 在浏览器中,我得到结果. 我搜索了我的错误,发现了这个问题:

As a note when i call my service url http://reporting.demo.ir/MonitoringInquiryService.svc/SearchInquiryStatus/null/'20171106'/'20171113' in browser i get the result . I googled my error and i found this :

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

我将此添加到我的UI Web配置中,但是出现相同的错误.

I added this to my UI web config .but i get same error.

推荐答案

您的UI项目似乎在ASP.NET MVC框架中,在其中无法从web.config设置中读取JavaScriptSerializer MaxJsonLength,正如您在问题.

Your UI project seems to be in ASP.NET MVC framework where JavaScriptSerializer MaxJsonLength cannot be read from web.config setting as you've specified in the question.

对于设置MaxJsonLength,您需要通过以下方式在代码中指定值:

For setting MaxJsonLength, you need to specify value in the code in following way :

var javascriptserializer = new JavaScriptSerializer()
{
    MaxJsonLength = Int32.MaxValue // specify length as per your business requirement
};

这篇关于字符串的长度超过了在maxJsonLength属性上设置的值.c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆