Skip to content

Instantly share code, notes, and snippets.

@dsibinski
Created August 15, 2021 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsibinski/9c1decb2cf139f8078d31d470f643f21 to your computer and use it in GitHub Desktop.
Save dsibinski/9c1decb2cf139f8078d31d470f643f21 to your computer and use it in GitHub Desktop.
class Person
{
public string Name { get; set; }
public Person BestFriend { get; set; }
}
[HttpGet]
public ActionResult TestPeopleData()
{
var john = new Person { Name = "John" };
var alicia = new Person { Name = "Alicia", BestFriend = john };
var mark = new Person { Name = "Mark", BestFriend = john };
var people = new List<Person> { john, alicia, mark };
var json = JsonConvert.SerializeObject(people, Formatting.Indented,
new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects });
return Content(json, "application/json");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment