Convert List Object to JSON in C#

Conversion of object to Json is pretty simple, can be easily achieved by adding Newtonsoft JSON.NET dll to the solution. While the object is list follow the below code to convert to the pure JSON format.

Wrapper Class:

    public class ColorDeleteOutput
        public List<ResponseMessage> Response { get; set; }

    public class ResponseMessage
        public string StyleNumber { get; set; }
        public string ColorLongDesc { get; set; }
        public string DistroDesc { get; set; }
        public string Status { get; set; }

Adding value to Objects:

List<ResponseMessage> respmsg = new List<ResponseMessage>();

respmsg.Add(new ResponseMessage { ColorLongDesc = "BLUE", StyleNumber = "124578", DistroDesc = "MARIO BRACKEN", Status = "SUCCESS" });

Converting to JSON:

  string sJSONResponse = JsonConvert.SerializeObject(respmsg);

[ Note : Make sure that you have added Newtonsoft Json.Net dll and Add its namespace as using Newtonsoft.Json; ]