、あなたはグローバルなデフォルトを設定することができます。
たとえば、あなたはのApplication_Start()メソッドでそれを行うことができます。過負荷と
シングルJsonConvert
:
// Option #1.
JsonSerializerSettings config = new JsonSerializerSettings { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore };
this.json = JsonConvert.SerializeObject(YourObject, Formatting.Indented, config);
// Option #2 (inline).
JsonConvert.SerializeObject(YourObject, Formatting.Indented,
new JsonSerializerSettings() {
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
}
);
Global.asax.csでApplication_Start()
のコードでを設定するグローバル:
JsonConvert.DefaultSettings =() => new JsonSerializerSettings {
Formatting = Newtonsoft.Json.Formatting.Indented,
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
};
参考:https://github.com/JamesNK/Newtonsoft.Json/issues/78
あなたはコントローラやアクションごとにこれを行うことができますか? – Chazt3n
これは、HangFireがインストールされたASP.NETアプリで動作することができません。間違ったlibararyなどを参照しています。デフォルト設定で他の答えを使用しなければなりませんでした。 – ppumkin