Created
August 15, 2021 05:07
-
-
Save dsibinski/9c1decb2cf139f8078d31d470f643f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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