Click here to Skip to main content
14,838,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I convert a string to a List object with Newtonsoft.

data2 has the string to list error.
C#
        string json2 = "[{\"id\":\"1\",\"datetime\":\"04/10/2017\",\"col1\":\"1\",\"col2\":\"2\",\"col3\":\"3\"}]";
        List<data> data2 = JsonConvert.DeserializeObject<List<data>>(json2);

public class data
    {
        public int id { get; set; }
        public string datetime { get; set; }
        public int col1 { get; set; }
        public int col2 { get; set; }
        public int col3 { get; set; }
    }


What I have tried:

I have tried different serialization string types.
Posted
Updated 13-May-17 7:54am
v3
Comments
Karthik_Mahalingam 21-Apr-17 4:31am
   
what is the error?
Tested your code, it works fine

1 solution

Your code should be:

data mydata = JsonConvert.DeserializeObject<data>(json2);
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900