简体   繁体   English

字符串的长度超过maxJsonLength属性c上设置的值。

[英]The length of the string exceeds the value set on the maxJsonLength property.c#

I am trying to get the result from my wcf service in json as you can see : 我试图从json中的wcf服务获得结果,如您所见:

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);
}

But i get this error : 但我得到这个错误:

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

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 . 当我在浏览器中调用我的服务URL http://reporting.demo.ir/MonitoringInquiryService.svc/SearchInquiryStatus/null/'20171106'/'20171113' ,我会得到结果。 I googled my error and i found this : 我搜索了我的错误,我发现了这个:

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

I added this to my UI web config .but i get same error. 我将此添加到我的UI web配置。但我得到相同的错误。

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. 您的UI项目似乎是在ASP.NET MVC框架中,无法从您在问题中指定的web.config设置中读取JavaScriptSerializer MaxJsonLength

For setting MaxJsonLength , you need to specify value in the code in following way : 要设置MaxJsonLength ,您需要按以下方式在代码中指定值:

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

Add this line in your function. 在你的函数中添加这一行。

 var javascriptserializer = new JavaScriptSerializer();
javascriptserializer.MaxJsonLength = Int32.MaxValue;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 字符串的长度超过maxJsonLength属性上设置的值 - length of the string exceeds the value set on the maxJsonLength property 字符串的长度超过了 mvc 中 maxjsonlength 属性上设置的值 - the length of the string exceeds the value set on the maxjsonlength property in mvc MVC4错误:字符串的长度超过了在maxJsonLength属性上设置的值 - MVC4 error: The length of the string exceeds the value set on the maxJsonLength property 正在检测字符串的长度超过在服务器上的maxJsonLength属性上设置的值 - Detecting The length of the string exceeds the value set on the maxJsonLength property at the server 我收到“字符串的长度超过 maxJsonLength 属性上设置的值” - I am getting a “The length of the string exceeds the value set on the maxJsonLength property” 错误“字符串的长度超过了 maxJsonLength 属性上设置的值。” - Error 'The length of the string exceeds the value set on the maxJsonLength property.' ASP.Net WebForm c#Web服务-字符串的长度超过在maxJsonLength属性上设置的值 - ASP.Net WebForm c# WebService - The length of the string exceeds the value set on the maxJsonLength property 尝试将部分视图转换为字符串时,“字符串的长度超出了在maxJsonLength属性上设置的值。” - “The length of the string exceeds the value set on the maxJsonLength property.” when trying to convert a partial view to string 使用JSON JavaScriptSerializer时发生错误“字符串的长度超过了在maxJsonLength属性上设置的值” - Error when using JSON JavaScriptSerializer “The length of the string exceeds the value set on the maxJsonLength property” JavaScript中View转换ViewBag.JsonData时,得到 The length of the string exceeds the value set on the maxJsonLength property - While converting ViewBag.JsonData from View in JavaScript, getting The length of the string exceeds the value set on the maxJsonLength property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM