JavaScriptSerializer maxJsonLength被忽略 [英] JavaScriptSerializer maxJsonLength ignored

查看:80
本文介绍了JavaScriptSerializer maxJsonLength被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家早上好,
我在编写返回JSON的Web服务时遇到了麻烦.调用该服务时,我收到了超出MaxJsonLength的错误(长度约为172k(包括JSON语法),或者为44k(不包含JSON语法),不确定是否相关?).我试图在我的WebMethod中将最大长度设置为我的JavaScriptSerializer,但这似乎没有任何区别,这是我的代码:-

Good Morning all,
I''m having trouble with a web service I''ve written which returns JSON. When the service is called I am getting a MaxJsonLength exceeded error (length is about 172k including JSON syntax, or 44k without, not sure which is relevant?). I have tried to set the max length to my JavaScriptSerializer within my WebMethod, but it doesn''t seem to make any difference, here is my code :-

JavaScriptSerializer js = new JavaScriptSerializer();
                js.MaxJsonLength = Int32.MaxValue; //I have tried multiple values
                string strJSON = js.Serialize(JaggedArray);
                return strJSON;



如果我逐步调试,则似乎设置了最大长度,并且如果我从.asmx调用该方法,结果返回的很好,则仅当我通过jQuery ajax调用从页面中调用该方法时,才会发生错误. br/>
有谁可以帮忙吗?

欢呼声
Gib



if I step through in debug, the max length appears to be set, and if I call the method from the .asmx the results come back fine, the error only occurs when I call the method from my page via a jQuery ajax call.

can any one help?

Cheers
Gib

推荐答案

显然在我的Web配置末尾添加以下内容可以解决我的问题,为什么,当配置中最初没有设置时,我的maxJsonLength硬编码了在网络方法不起作用,我不知道,但没关系嘿? :doh:

Apparently adding the following at the very end of my web config sorted my problem, why, when there was none originally set in the config, my maxJsonLength hard coded in the web method didn''t work I have no idea, but never mind hey? :doh:

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


这篇关于JavaScriptSerializer maxJsonLength被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆