序列化为 JSON 时出现 OutOfMemoryException?

Getting an OutOfMemoryException while serialising to JSON?(序列化为 JSON 时出现 OutOfMemoryException?)
本文介绍了序列化为 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)