Newtonsoft.json 中的 ReferenceLoopHandling.Ignore 究竟做了什么?

What does ReferenceLoopHandling.Ignore in Newtonsoft.json exactly do?(Newtonsoft.json 中的 ReferenceLoopHandling.Ignore 究竟做了什么?)
本文介绍了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?

     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)



The documentation on this is available here:


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 究竟做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)