我使用下面的代码获取大约17 MB的PPTX文件的数组(如果任何文件小于15 MB,这可以正常工作)。在jss.Deserialize
行,它会抛出错误“类型'Exception of System.OutOfMemoryException'”
JavaScriptSerializer jss = new JavaScriptSerializer { MaxJsonLength = 2147483644, RecursionLimit = 100 };
var requestJson = jss.Serialize(new { serverRelativeUrl = serverRelativeUrl, token = token });
WebClient wClient = new WebClient();
wClient.Headers["Content-Type"] = "text/json; charset=utf-8";
var data = wClient.UploadData(serviceMethodURL, "POST", Encoding.UTF8.GetBytes(requestJson));
var responseJson = Encoding.UTF8.GetString(data);
var response = jss.Deserialize<MethodResponse<byte[]>>(responseJson);
有什么想法吗?我坚持这个。请帮忙
答案 0 :(得分:0)
我使用
解决了这个问题MethodResponse<byte[]> response = null;
using (System.IO.MemoryStream stream1 = new System.IO.MemoryStream(data))
{
System.Runtime.Serialization.Json.DataContractJsonSerializer ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(MethodResponse<byte[]>));
stream1.Position = 0;
response = (MethodResponse<byte[]>)ser.ReadObject(stream1);
}
return response;