什么是ReferenceLoopHandling.Ignore在Newtonsoft.json究竟怎么办? [英] What does ReferenceLoopHandling.Ignore in Newtonsoft.json exactly do?

查看:541
本文介绍了什么是ReferenceLoopHandling.Ignore在Newtonsoft.json究竟怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以present我一个方案,其中它可以被使用。 我的理解通过的 ReferenceLoopHandling.Ignore 是,如果你序列化时,得到了一个对象A中的参考对象B和B引用C和C再次引用(ABCA),那么,它最终会之间的死循环C和A,其可以使用下面被避免。我说得对?

Can anyone present me a scenario where it can be used. What I understand by ReferenceLoopHandling.Ignore is if you got 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 want to understand exactly what it is doing as the above line is the meat of the application (critical meat)

推荐答案

在这个文档可以在这里找到:<一href="http://james.newtonking.com/projects/json/help/html/SerializationSettings.htm">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.Ignore: Json.NET will ignore objects in reference loops and not serialize them. The first time an object is encountered it will be serialized as usual but if the object is encountered as a child object of itself the serializer will skip serializing it.

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.

这篇关于什么是ReferenceLoopHandling.Ignore在Newtonsoft.json究竟怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆