【发布时间】:2015-03-27 23:05:00
【问题描述】:
我有一个 .Net Web 服务 (.asmx),它将向我的客户端返回一个 Json 字符串。但是,我的一些数据确实很大,我偶尔会收到此错误。
字符串的长度超过了 maxJsonLength 属性设置的值。
我已将 maxJsonLength 属性更改为 2147483644,但它仍然不起作用。请帮忙...谢谢。
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetData(string login)
{
// throw an error on this line...
string result = new JavaScriptSerializer().Serialize(service.GetData(login));
Context.Response.Write(result);
}
【问题讨论】:
-
this question (and its answers) 能解决您的问题吗?
-
George - @NextInLine 链接中的第二个答案是您想要的答案:将
maxJsonLength设置为new JavaScriptSerializer的属性。链接中的第一个答案对您没有帮助。 -
您说您使用的是"Newtonsoft.Json",但在您的代码中您使用的是
JavaScriptSerializer。只是为了确认一下,您没有使用 Newtonsoft.Json,对吧? -
@dbc:是的,你是对的。在这种情况下,我没有使用 Newtonsoft Json。我将它用于另一种方法。我很抱歉造成混乱。我会更新我的问题。谢谢:-)
-
@Ed Gibbs:嗨,Ed,谢谢。你的建议有效!我用的是第二个。
标签: c# json web-services