Link to home
Start Free TrialLog in
Avatar of robnhood00
robnhood00

asked on

Convert vb.net object to JSON

Is there an easy way to convert an object to JSON in Vb.net?  Something like object.ToJSON?
 
Public Class MyURL
    Public Property URL As String
    Public Property Description As String
    Public Property DateAdded As String
End Class
Protected Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load
        Dim p As New MyURL
        Dim s As New List(Of MyURL)

        p.URL = "http://google.com"
        p.Description = "Test Item 1"
        p.DateAdded = "1/1/2013"

        s.Add(p)

        p.URL = "http://yahoo.com"
        p.Description = "Test Item 2"
        p.DateAdded = "12/15/2012"

        s.Add(p)

        'Is there a simple toJSON function that can be used?
        response.write(s.toJson)
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or you can just use the built in JavascriptSerializer in .net

Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim jsonString = serializer.Serialize(s)

Response.Write(jsonString)

Open in new window