An error occurred while serializing or deserializing using the JSON JavaScriptSerializer.

An error occurred while serializing or deserializing using the JSON JavaScriptSerializer. The string length exceeds the value specified for 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);
    }

      

+3


source to share


1 answer


I am assuming this is the web service from which you are fetching data (as your question is tagged as "web service"), change the 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 JavaScriptSerializer:

JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue; 
myObject obj = serializer.Deserialize<yourObject>(yourJsonString);

      

+9


source







All Articles