return 大量记录 json

To return large number of records in json

在下面的代码中,我在 datatable 中获取值并返回为 jsonconvert,但这些值没有返回。有近3000条记录。如果有几条记录,它会返回。

[WebMethod]
    public static string GetDescriptions() 
    {
        string strLocation = "1";
        MastersClient objProductName = new MastersClient();

        DataSet Product = objProductName.GetLocationProductMap(int.Parse(strLocation));

        DataTable customerTable = Product.Tables[0];
        var serializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };

        return JsonConvert.SerializeObject(customerTable).ToString();
    }

确保响应不会太大。您可以在配置文件中增加响应大小 (web.config):

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

调整 maxJsonLength 以满足您的需求,但请记住,太大的响应会导致用户等待更长时间。

编辑:您可能还需要在 appSettings 下添加此键:

<add key="aspnet:MaxJsonDeserializerMembers" value="50000"/>

下面的代码将帮助你...

        var serializer = new JavaScriptSerializer()
        serializer.MaxJsonLength = Int32.MaxValue