[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4197
  • Last Modified:

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

0
robnhood00
Asked:
robnhood00
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
Snarf0001Commented:
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

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now