![](/img/trans.png)
[英]length of the string exceeds the value set on the maxJsonLength property
[英]ASP.Net WebForm c# WebService - The length of the string exceeds the value set on the maxJsonLength property
我正在使用ASP.Net WebForm和C#Web服务,并且在运行我的代码时遇到以下错误;
Error during serialization or deserialization using the JSON JavaScriptSerializer.
The length of the string exceeds the value set on the maxJsonLength property.
我尝试将以下内容放入Web配置中,但尚未解决。
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
我的网络服务;
public class OpenRequisitions
{
public string string1 { get; set; }
public string sstring2 { get; set; }
public string string3 { get; set; }
public string string4 { get; set; }
public string string5 { get; set; }
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<OpenRequisitions> GetOpenReqData(string ReqId, string RequisitionTitle, string City, string Country, string DateCreated)
{
string connectionString = ConfigurationManager.ConnectionStrings["CONN"].ConnectionString;
string commandTextGetOpenRequisitions = Properties.Queries.commandTextGetOpenRequisitions;
List<OpenRequisitions> GetOpenRequisitionData = new List<OpenRequisitions>();
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(commandTextGetOpenRequisitions, con);
command.CommandType = CommandType.Text;
con.Open();
SqlDataReader rdr = command.ExecuteReader();
while (rdr.Read())
{
OpenRequisitions results = new OpenRequisitions();
results.ReqId = rdr["string1"].ToString();
results.RequisitionTitle = rdr["string2"].ToString();
results.City = rdr["string3"].ToString();
results.Country = rdr["string4"].ToString();
results.DateCreated = rdr["string5"].ToString();
GetOpenRequisitionData.Add(results);
}
}
return GetOpenRequisitionData;
}
看来问题与JavaScriptSerializer有关。 您可以直接在其上设置最大值。 它不会从web.config继承值。
// Create an instance of your JavaScriptSerializer and set the MaxJsonLength.
var serializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
// Perform your serialization
serializer.Serialize("Your JSON Contents");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.