在.net mvc的controller中,方法返回JsonResult,一般我们这么写:

[HttpPost]
public JsonResult QueryFeature(string url, string whereClause)
{
      string str="";
      return Json(str);
}

  此时如果str过长,就会报“使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错,字符串的长度超过了为 maxJsonLength 属性设置的值”

  解决方法如下:

  

[HttpPost]
public JsonResult QueryFeature(string url, string whereClause)
{
            string str="";
            
            return new JsonResult()
            {
                Data = str,
                MaxJsonLength = int.MaxValue,
                ContentType = "application/json"
            };
}

 

相关文章:

  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-13
  • 2021-11-29
相关资源
相似解决方案