[Solved] How to convert Multiple Json object to DataTable or DataSet in C#


You can check it here How to create dataset from Object?

There are a lot of ways you can use to instantiate an object from json string.

If you can’t use any kind of third party libraries such as Newtonsoft.Json you can do it with JsonReaderWriterFactory

public static TEntity Create<TEntity>(string json)
{
    using (var memoryStream = new MemoryStream())
    {
        byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
        memoryStream.Write(jsonBytes, 0, jsonBytes.Length);
        memoryStream.Seek(0, SeekOrigin.Begin);
        using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(
            memoryStream,
            Encoding.UTF8,
            XmlDictionaryReaderQuotas.Max,
            null))
        {
            var     serializer = new DataContractJsonSerializer(typeof(TEntity));
            TEntity entity     = (TEntity)serializer.ReadObject(jsonReader);
            return entity;
        }
    }
}

And vice-versa

public static string Create(object entity)
{
    var serializer = new DataContractJsonSerializer(entity.GetType());

    using (var stream = new MemoryStream())
    {
        using (var writer = JsonReaderWriterFactory.CreateJsonWriter(stream, Encoding.UTF8))
        {
            serializer.WriteObject(writer, entity);
        }

        return Encoding.UTF8.GetString(stream.ToArray());
    }
}

Then you will only need to work a little bit with C# to populate the required DataSet with your object instance.

Here is my code

1

solved How to convert Multiple Json object to DataTable or DataSet in C#