C# – Converting a dataset to JSON using .NET 3.5 in C#


I have been searching for a simple way to convert a dataset from a PostgreSQL database to JSON for use in a project that I am building.

This is my first time using JSON, and I have found it really tricky to find a simple way of doing this. I have been using a StringBuilder at the moment to create a JSON string from the information in the dataset, but I have heard that it is possible to do this very simply with .NET 3.5 using the System.Runtime.Serialization namespace, though I have yet to find a simple article or blog on how this is done! What is the easiest way to do this?

Best Solution

Use Newtonsofts Json.Net and check out DataTable JSON Serialization in JSON.NET and JavaScriptSerializer where it's used to create a DataSet-to-JSON converter.