字符串长度超过maxJsonLength设置的值property.c#
The length of the string exceeds the value set on the maxJsonLength property.c#
我正在尝试从 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);
}
但是我得到这个错误:
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
当我打电话给我的服务时请注意 url http://reporting.demo.ir/MonitoringInquiryService.svc/SearchInquiryStatus/null/'20171106'/'20171113'
在浏览器中我得到了结果。
我用谷歌搜索了我的错误,发现了这个:
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
我将其添加到我的 UI 网络配置中。但我得到了同样的错误。
在您的函数中添加这一行。
var javascriptserializer = new JavaScriptSerializer();
javascriptserializer.MaxJsonLength = Int32.MaxValue;
您的 UI 项目似乎在 ASP.NET MVC 框架中,其中 JavaScriptSerializer
MaxJsonLength
无法从 web.config 设置中读取,正如您在这个问题。
要设置MaxJsonLength
,您需要在代码中按以下方式指定值:
var javascriptserializer = new JavaScriptSerializer()
{
MaxJsonLength = Int32.MaxValue // specify length as per your business requirement
};
我正在尝试从 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);
}
但是我得到这个错误:
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
当我打电话给我的服务时请注意 url http://reporting.demo.ir/MonitoringInquiryService.svc/SearchInquiryStatus/null/'20171106'/'20171113'
在浏览器中我得到了结果。
我用谷歌搜索了我的错误,发现了这个:
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
我将其添加到我的 UI 网络配置中。但我得到了同样的错误。
在您的函数中添加这一行。
var javascriptserializer = new JavaScriptSerializer();
javascriptserializer.MaxJsonLength = Int32.MaxValue;
您的 UI 项目似乎在 ASP.NET MVC 框架中,其中 JavaScriptSerializer
MaxJsonLength
无法从 web.config 设置中读取,正如您在这个问题。
要设置MaxJsonLength
,您需要在代码中按以下方式指定值:
var javascriptserializer = new JavaScriptSerializer()
{
MaxJsonLength = Int32.MaxValue // specify length as per your business requirement
};