仅在非常大的集合上,以下行在服务器级别的 mscorlib.dll 处引发 OutofMemroyException
HttpResponseMessage response;
response.Content= new StringContent(JsonConvert.SerializeObject(results),
system.Encoding.UTF8, "text/json");
但是,以下序列化同一对象的方法不会产生此错误
Var serializer= new System.Web.Script.Serilaization.JavascriptSerializer()
{MaxJsonLength = int.MaxValue};
response.Content= new StringContent(serializer.Serialize(results),
system.Encoding.UTF8, "text/json")
但是,使用第二种方法时,客户端会引发错误:
无法反序列化当前的 json 数组,因为该类型需要 json 对象
所以我希望要么用第一种方法解决内存问题,要么弄清楚为什么第二种方法可以像第一种方法一样反序列化
谢谢