how to convert list to json in c# mvc

1 Answers

  1. Aditya Kumar Patel
    Re:how to convert list to json in c# mvc
    10/10/2018 7:12:05 PM

    By using newtonsoft json we can easily convert list object to JSON string in c#. Following are the methods to convert list object to JSON string in c#.
    Try to use it:

     

    List<Employee> Employee = new List<Employee>(){
                new Employee() {  Name = "Suresh", ID  = 1},
                new Employee() {  Name = "Sekher", ID =  2 },
                  new Employee() {  Name = "Sumit", ID =  3 },
                new Employee() {  Name = "Pankaj", ID = 4 },
                new Employee() {  Name = "Rahul", ID = 5 }}.ToList();

     

    following code convert employee list to json string.

     

    string strJson = JsonConvert.SerializeObject(Employee);

    I hope it will help to you.


Leave a answer

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like