简体   繁体   English

ASP.Net WebForm c#Web服务-字符串的长度超过在maxJsonLength属性上设置的值

[英]ASP.Net WebForm c# WebService - The length of the string exceeds the value set on the maxJsonLength property

I'm using ASP.Net WebForm & a C# Web Service and am getting the below error when running my code; 我正在使用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.

I've tried putting the below into the web config but it's not resolved it; 我尝试将以下内容放入Web配置中,但尚未解决。

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

My Web Service; 我的网络服务;

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

It looks like the problem is related to JavaScriptSerializer. 看来问题与JavaScriptSerializer有关。 You can set a max value on that directly. 您可以直接在其上设置最大值。 It doesn't inherit the value from web.config. 它不会从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"); 

Source 资源

暂无
暂无

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

相关问题 字符串的长度超过maxJsonLength属性上设置的值 - length of the string exceeds the value set on the maxJsonLength property 字符串的长度超过maxJsonLength属性c上设置的值。 - The length of the string exceeds the value set on the maxJsonLength property.c# 字符串的长度超过了 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.' 尝试将部分视图转换为字符串时,“字符串的长度超出了在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” 如何在HtmlTextWriter asp.net c#webform中追加字符串 - how to append string in a HtmlTextWriter asp.net c# webform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM