1

I have a json string and would like to make a DataTable from it.

How can I convert JSON to a DataTable in C#?

Update:

I have used Json.Net as per link provided here

and build 2 class to to handle json string as per below

 public class JsonHelper
        {
            public List<User> userdata { get; set; }
        }

  public class User
    {
        public string name { get; set; }
        public string id { get; set; }
        public DateTime createdDate { get; set; }

    }

and use following code to Deserialize

Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();

            json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
            json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
            json.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

            StringReader sr = new StringReader(jsonstr);
            Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
            object result = json.Deserialize(reader, typeof( JsonHelper));
            reader.Close();

            return result;

but getting following error

Cannot deserialize JSON array into type 'mynamespace+JsonHelper'.

What should be problem here , please help me to sort out this problem.

thanks.

0

1 Answer 1

1

This post by Rick Strahl may help you out. Under the covers he's using Newtonsoft's JSON.NET libraries to do the heavy lifting.

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried to use this but getting error please see my updated question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.