Getting an OutOfMemoryException while serialising to JSON?(序列化为 JSON 时出现 OutOfMemoryException?)
问题描述
我正在序列化,一个MultiDictionary<String,Object>
http://powercollections.codeplex.com/到 json .
它有 618 个元素,元素被深度嵌套,即单个对象中可能有几个类似字典的对象.我正在使用 JSON.Net
It has 618 elements with elements being deeply nested ,i.e. a single Object may have several dictionary like objects in it . I am using JSON.Net
String json = JsonConvert.SerializeObject(json, Newtonsoft.Json.Formatting.Indented);
我错过了什么?
更多信息:-这在我使用动态之前工作正常,我不得不切换到 MultiDictionary 以允许多个同名属性.它适用于大多数情况,只有当项目数量很大时才会中断.
MORE INFO: - This was working fine till i was using dynamic , i had to switch to MultiDictionary to allow multiple properties of the same name . It works for most cases , only when the number of items is large , it breaks .
更新:-
我已经能够控制内存消耗,但减少了一些递归添加到每个元素的元素.
I have been able to get a hold of the Memory consumption but cutting down on some elements that were getting added recursively to each element.
推荐答案
您似乎遇到了 Ciruclar Reference 导致 OutOfMemoryException
或您的对象对您的内存来说太大了.使用 NDepend 进行检查.
It appears that you're running into Ciruclar Reference that is causing OutOfMemoryException
or your objects are simply too large for your memory. Use NDepend to check this.
您可能会发现获取对象的总大小很有用一个>.
这篇关于序列化为 JSON 时出现 OutOfMemoryException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:序列化为 JSON 时出现 OutOfMemoryException?


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01