We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Error during serialization or deserialization with JavaScriptSerializer of JSON

Hi,

I want populate a grid and I get this error.

I set this configuration in web config

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

Also I read this post:

http://www.syncfusion.com/forums/117447/error-serialize-json-in-grid

And I have doubts:

- When I load the grid, it's always with loading icon

- If I've 3 or 4 or more grids, I need rewrite the script loadHandler in each page


Is not there an easier way to load data?

Thanks

3 Replies

GV Gowthami V Syncfusion Team April 1, 2015 09:25 AM UTC

Hi Manolo,
Thanks for using Syncfusion products.
Query 1: I want populate a grid and I get this error.

The issue “Error during serialization or deserialization with JavaScriptSerializer of JSON” can be resolved by using WebMethodAdaptor, which is used for performing server side operations.
Please refer the below KB link for more clarification about WebMethodAdaptor.

KB Link: http://www.syncfusion.com/kb/4300/server-side-api-for-datamanager-operations
Query 2: When I load the grid, it's always with loading icon and If I've 3 or 4 or more grids, I need rewrite the script loadHandler in each page

With the reference of the forum (#117447), we found that the response was provided on October 23, 2014, whereas we did not have support for BatchURL at that time. So that we have extended the adaptor in load event of the grid and bind the data source from the server side. Now in the latest version, the below code is not necessary.

var adaptor = new ej.UrlAdaptor().extend({

processResponse: function (data, ds, query, xhr, request, changes) {

return data.d;

}

});

function loadHandler(args) {

args.model.dataSource.dataSource.batchUrl = "Default.aspx/Update"

args.model.dataSource.adaptor = new adaptor();
}

public static object Data(int skip, int take)

{

var DataSource = OrderRepository.GetAllRecords();

DataResult ds = new DataResult();

ds.result=DataSource.Skip(skip).Take(take);

ds.count= ds.count = DataSource.Count();

return ds;
}

Instead of the above code we can use the WebMethodAdaptor for performing on demand paging as follows.

<ej:Grid ID="EmployeesGrid" runat="server" Width="1500px" AllowPaging="true" >
<DataManager URL="Default.aspx/Data" Adaptor="WebMethodAdaptor" />

<ej:Grid>

[WebMethod]

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

public static object Data(Syncfusion.JavaScript.DataManager value)

{

IEnumerable Data = OrderRepository.GetAllRecords();

int count = Data.AsQueryable().Count();

Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();

Data = operation.Execute(Data, value);

return new { result = Data, count = count };
}


For your convenience we have create a sample with WebMethodAdaptor and the same can be downloaded from the following link.
Sample Link: Sample.zip
Please try the sample and let us know if you have any queries.
Regards,
Gowthami V.


MA Manolo April 2, 2015 02:49 PM UTC

Thank you very much!


GV Gowthami V Syncfusion Team April 6, 2015 02:35 PM UTC

Hi Manolo,

Thanks for your update.

Please get back to us if you need further assistance. We will happy to assist you.

Regards,
Gowthami V.



Loader.
Live Chat Icon For mobile
Up arrow icon