Question

Does anyone know how to convert VB.net datatable to JSON using ServiceStack JsonSerializer?

On ServiceStack Docs website you can find following example but this is C#, plus I cannot understand the way this works.

string TypeSerializer.SerializeToString<T>(T value);
void TypeSerializer.SerializeToWriter<T>(T value, TextWriter writer);

T TypeSerializer.DeserializeFromString<T>(string value);
T TypeSerializer.DeserializeFromReader<T>(TextReader reader);

Example datatable

Dim table As New DataTable
        table.Columns.Add("Dosage", GetType(Integer))
        table.Columns.Add("Drug", GetType(String))
        table.Columns.Add("Patient", GetType(String))
        table.Columns.Add("Date", GetType(DateTime))
        table.Rows.Add(25, "Indocin", "David", DateTime.Now)
        table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
        table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now)
        table.Rows.Add(21, "Combivent", "Janet", DateTime.Now)
        table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now)

Any suggestions much appreciated.

Était-ce utile?

La solution

ServiceStacks JSON Serializer does not support serializing DataTables directly. You would need to convert them to POCOs and serializer those.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top