.net MVC 使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错,字符串的长度超过了为 maxJsonLength 属性设置的值

简介: 在.net mvc的controller中,方法返回JsonResult,一般我们这么写: [HttpPost] public JsonResult QueryFeature(string url, string whereClause) { string str=""; return Json(str); }   此时如果str过长,就会报“使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错,字符串的长度超过了为 maxJsonLength 属性设置的值”。

在.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"
            };
}

 

相关文章
|
1月前
|
存储 JSON JavaScript
Python字典和JSON字符串相互转化方法
【2月更文挑战第18天】
59 3
|
4月前
|
JSON JavaScript 数据格式
JS 将 json 对象转成字符串并保留格式 - JSON.stringify()
JS 将 json 对象转成字符串并保留格式 - JSON.stringify()
61 0
|
1月前
|
JSON Java Maven
使用Jackson进行 JSON 序列化和反序列化
使用Jackson进行 JSON 序列化和反序列化
23 0
|
1月前
|
XML 存储 BI
如何把一个 ABAP 类的实例,序列化成 XML 字符串试读版
如何把一个 ABAP 类的实例,序列化成 XML 字符串试读版
12 0
|
1月前
|
JSON JavaScript PHP
PHP把unicode编码的json字符串转中文
PHP把unicode编码的json字符串转中文
13 0
|
6月前
|
JSON Java fastjson
简单实现_实体类与Json字符串互相转换
简单实现_实体类与Json字符串互相转换
54 1
|
3月前
|
JSON JavaScript Android开发
JS生成JSON字符串---autojs pro 篇
JS生成JSON字符串---autojs pro 篇
25 0
|
3月前
|
JSON Java fastjson
Java中的JSON序列化和反序列化
Java中的JSON序列化和反序列化
|
3月前
|
JSON 前端开发 JavaScript
将 JavaScript 对象或值转换为 JSON 字符串:JSON.stringify()
将 JavaScript 对象或值转换为 JSON 字符串:JSON.stringify()
71 3
|
4月前
|
JSON 数据格式
gson自定义Type解析json数组字符串
gson自定义Type解析json数组字符串

热门文章

最新文章