1

I have a jquery/ajax call to my web method defined in my C# code behind page in asp.net.

I am trying to return a string array of 2000 items.

I get an undefined error.

If the array is less than 400 it works OK.

So the problem is how I am returning large arrays to the jquery call.

I am returning from my web method this:

string[]

Is there a limit to the amount of items in an array i can return or do i have to parse it somehow to something json accepts?

New at this game so appreciate advice.

//client side

jQuery(function ($) {
    $.ajax({
        type: "POST",
        url: "Feed.aspx/PlayClips",
        data: JSON.stringify({
            ClipValue: lstMotionClips.options[lstMotionClips.selectedIndex].value,
            SessionID: sessionID,
            alias: alias
        }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {

            $.each(msg.d, function () {
                if (this['Text'] == "ERROR") {
                    alert(this['Value']);
                }
                else {

                    arrayresult = msg.d;
                    totalFrames = arrayresult.length;
                    PlayBack();
                }
            });    
        },
        error: function (msg) {
            alert(msg.d);}
    })
});

//server side

[WebMethod]
public static string[] PlayClips(string ClipValue, string SessionID, string alias)
{
    string[] frames = null;
    try
    {       
        string[] parentDirectory = Directory.GetDirectories(parentPath, guid, SearchOption.AllDirectories);
        if (parentDirectory.Length > 0)
        {
             frames = Directory.GetFiles(parentDirectory[0], "*.jpg", SearchOption.TopDirectoryOnly);
        }
    }
    catch (Exception _ex)
    {
        dalStatic.AddError("PlayClips." + _ex.ToString());
    }
    return frames;
}

Thanks

NB I have checked the total length of the string when the error starts.

It appears that a length of string up to 14188 is OK. As soon as I go beyond that I get the error. So, a threshold has been reached. I have set the MaxStringContent toa very high number but still get the error.

Andrew Simpson
  • 6,883
  • 11
  • 79
  • 179

1 Answers1

2

Json have limits see here-->http://msdn.microsoft.com/en-us/library/system.web.configuration.scriptingjsonserializationsection.maxjsonlength.aspx

change web.config somthing similarly

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

Ratna
  • 2,289
  • 3
  • 26
  • 50
  • hi, this was what I suspected and this was the answer I was hoping for. I am getting an error though when I put that in and I am trying to trace it as I type. ERROR: The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration – Andrew Simpson Jan 03 '14 at 09:08
  • 1
    see here http://stackoverflow.com/questions/20063861/the-configuration-section-system-web-extensions-cannot-be-read-because-it-is-m – Ratna Jan 03 '14 at 09:15