简体   繁体   中英

serialize datatable to JSON issue vb.net

Ok, I'm trying to serialize a data table in vb.net:

Dim dt As New System.Data.DataTable

and for the serializer:

Dim js As JavaScriptSerializer = New JavaScriptSerializer()
dim jsonString as string
jsonString=js.serialize(dt)

when it serialize the data table on the last line, it got an error:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Web.Extensions.dll

Additional information: A circular reference was detected while serializing an object of type 'System.Globalization.CultureInfo'

I even make the simplest datatable with only 1 column and 1 row, but it just won't serialize it,

I know that this kind of question was answered: in here

but I don't know how to implement the answer (make a new class), or maybe there's an even better solution?

As far as I know there is not out of the box serializer for DataTable objects. I ended up going with a full custom serialization. Another approach could be converting first your DataTable to an IEnumerable<> and then, serializing.

However, this link may be helpful: JSV

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM