Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error during serialization or deserialization using the JSON JavaScriptSerializer.

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

public string MemberDetail(string Code)
    {
        String res = "";
        SortedList sd = new SortedList();
        sd.Add("@mode", "MemberDetail");
        sd.Add("@Code", Code);
        SqlDataReader dr = erp.GetDataReaderSP("[Demo]", sd);
        DataTable dt = new DataTable();

        dt.Load(dr);
        Synchr[] obj = new Synchr[dt.Rows.Count];
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                obj[i].DemoName = Convert.ToInt32(dt.Rows[i]["Name"].ToString());
            }
        }

        return new JavaScriptSerializer().Serialize(obj);
    }
like image 435
Genish Parvadia Avatar asked Nov 14 '14 08:11

Genish Parvadia


1 Answers

I assume it is a web service that you are getting the data from (as your question is tagged "web-service"), change maxlength in web.config :

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

Or you can try the MaxJsonLength of JavaScriptSerializer :

JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue; 
myObject obj = serializer.Deserialize<yourObject>(yourJsonString);
like image 103
Zaki Avatar answered Nov 02 '22 16:11

Zaki