Skip to content Skip to sidebar Skip to footer

Vb.net Problem Converting Datatable To Json

Ok so I'm trying to use the JavaScriptSerializer to work with this code. However it crashes when it reaches the last line; Dim json As New String(sr.Serialize(dt)) I get this erro

Solution 1:

Circular reference means that serialising the object would result in an infinite loop. For example if you would try to serialize object "A" having a 1 to 1 reference to object "B".

Declare a class containg the data you want to serialize with JSON to solve this issue.

Solution 2:

As hkda150 has already said, you could use a class specifically tailored for being serialized.

This will furthermore enable you to have foreign key values serialized instead of having related full objects serialized. Thus, if you are serializing object a which has a property a.SomeB of type B, then you will often want the ID of a.someB to be present in your webpage. Obviously I don't know enough to be able to say if this is relevant in your specific use case.

BTW, If you find yourself doing a lot of mapping between "business objects" and "objects meant for serialization" you may want to consider using AutoMapper.

Post a Comment for "Vb.net Problem Converting Datatable To Json"