I want to use .Net Framework built-in library to convert my DataTable / DataSet to JSON. How is this possible.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
DataTable and DataSet objects cannot be JSON serialized directly. You’ll need to convert them first to something like
Once you do that, you can use JavaScriptSerializer to do the actual conversion to JSON.
Update based on your comment:
If you are trying to convert the data obtained from a SQL query into JSON, represent the data in a simple class first:
Read the results into:
Now, convert the list to JSON using JavaScriptSerializer.