【发布时间】:2015-04-06 23:01:37
【问题描述】:
我正在尝试使用 JSON JavaScriptSerializer 反序列化一个过大的字符串。我收到此错误。
" 使用 JSON 进行序列化或反序列化时出错 JavaScript 序列化器。字符串长度超过设置的值 在 maxJsonLength 属性上。”
HttpResponseMessage messge = client.GetAsync("ladders/get/d381241a0ad596d4bf02f441e75d1891fcc482e607c751e3978bc0adea6a9d99").Result;
string result = messge.Content.ReadAsStringAsync().Result;
string description = result;
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
var myobj = jsSerializer.Deserialize<List<List<CandidateResume>>>(description);
这是我的课
public class CandidateResume
{
public string name { get; set; }
public string url { get; set; }
public string summary { get; set; }
public string role { get; set; }
public string compensation { get; set; }
public string education { get; set; }
public string expertise { get; set; }
public string years { get; set; }
public string relocation { get; set; }
public string resume { get; set; }
public string resumeExtension { get; set; }
public string resumeMimeType { get; set; }
}
我已将 maxJsonLength 属性添加到 2147483644,但它仍然不起作用。
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
【问题讨论】:
-
我已经这样解决了 JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 }; var myobj = jsSerializer.Deserialize
- >>(description);
-
这个答案是最干净的。我知道你是几个月前发布的,也许你已经看过了:stackoverflow.com/questions/1151987/…
标签: c# json web-services asp.net-mvc-4