C# serialize list of objects to json Edit

Murugan Andezuthu Dharmaratnam | 17 September 2020 | 768

I have an object model that looks like the object below, how can I serialize the list to JSON.

public class Country
    public int Id { get; set; }
    public int Code { get; set; }
    public String Name { get; set; }

You can serialize the list of JSON using Newtonsoft.Json. Check the code below.

List<country> lstCountries = new Country().Get();
String countryJson = Newtonsoft.Json.JsonConvert.SerializeObject(lstCountries);

Here is the serialized JSON code.