What does ReferenceLoopHandling.Ignore in Newtonsoft.json exactly do?(Newtonsoft.json 中的 ReferenceLoopHandling.Ignore 究竟做了什么?)
问题描述
谁能给我一个可以使用它的场景.我对 ReferenceLoopHandling.Ignore 的理解是,如果您有一个引用对象 B 和 B 引用 C 和 C 再次引用 A (A->B->C->A) 的对象 A,那么在序列化时,它将在 C 和 A 之间陷入无限循环,可以使用下面的方法来避免.我说的对吗?
Can anyone present me a scenario where it can be used. What I understand by ReferenceLoopHandling.Ignore is if you have an object A which references object B and B references C and C again references A (A->B->C->A), then when serializing, it will end up in endless loop between C and A, which can be avoided using below. Am I right?
JsonConvert.SerializeObject(data,
Formatting.Indented,
new JsonSerializerSetting()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
));
我遇到了通过使用上述方法解决的自引用循环问题,但我想准确了解它在做什么,因为上面的行是应用程序的核心(关键肉)
I am having self referencing loop issue which gets solved by using the above, but I want to understand exactly what it is doing as the above line is the meat of the application (critical meat)
推荐答案
相关文档可在此处获得:http://james.newtonking.com/projects/json/help/html/SerializationSettings.htm
The documentation on this is available here: http://james.newtonking.com/projects/json/help/html/SerializationSettings.htm
在撰写本文时,该行为描述如下(重点是我的):
As of this writing, the behavior is described there as follows (with emphasis mine):
ReferenceLoopHandling.Error:默认情况下,Json.NET 会出错,如果遇到引用循环(否则序列化程序将进入一个无限循环).
ReferenceLoopHandling.Error: By default Json.NET will error if a reference loop is encountered (otherwise the serializer will get into an infinite loop).
ReferenceLoopHandling.Ignore:Json.NET 将忽略引用循环而不是序列化它们.第一次对象是遇到它会像往常一样被序列化,但如果对象是作为自身的子对象遇到的序列化程序将跳过序列化它.
ReferenceLoopHandling.Serialize:此选项强制 Json.NET在引用循环中序列化对象.如果对象是嵌套但不是无限期的.
ReferenceLoopHandling.Serialize: This option forces Json.NET to
serialize objects in reference loops. This is useful if objects are
nested but not indefinitely.
这篇关于Newtonsoft.json 中的 ReferenceLoopHandling.Ignore 究竟做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Newtonsoft.json 中的 ReferenceLoopHandling.Ignore 究竟做了什么?
基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
