c# - How to serialize as Json an object structure with circular references? -


i have object structure this:

public class proposal {     public list<proposalline> lines { get; set; }     public string title { get; set; } }  public class proposalline {     public proposal proposal { get; set; }  // <- reference parent object } 

i try serialize proposal json, tells me there circular reference, correct.
unfortunately, can't touch objects, since in referenced dll project - otherwise i'd change them.

is there way serialize json , ignore circular properties?

use newtonsoft.json (which default .net json serializer) , set

jsonserializersettings settings = new jsonserializersettings {     preservereferenceshandling = preservereferenceshandling.objects }; var serializer = jsonserializer.create(settings); 

you can globally define variable if developing mvc applications...


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -