top button
Flag Notify
Site Registration

How to Deserialize an Object in VB.NET using Json.NET ?

0 votes
376 views
How to Deserialize an Object in VB.NET using Json.NET ?
posted May 26, 2016 by Sathyasree
Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
Imports Newtonsoft.Json

Module Module1

    Sub Main()
        Dim jsonTxt As String = "{'Name': 'Abundantcode'," & vbCr & vbLf & "  'IsPermanent': true," & vbCr & vbLf & " 'Departments': [" & vbCr & vbLf & "    'Technology'," & vbCr & vbLf & "    'Product Engineering'" & vbCr & vbLf & "  ]" & vbCr & vbLf & "    }"

        ' Deserialize an Json string to Employee object 
        Dim emp As Employee = JsonConvert.DeserializeObject(Of Employee)(jsonTxt)

        Console.WriteLine(emp.Name)
        Console.ReadLine()
    End Sub
    Public Class Employee
    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set
            m_Name = Value
        End Set
    End Property
    Private m_Name As String
    Public Property IsPermanent() As Boolean
        Get
            Return m_IsPermanent
        End Get
        Set
            m_IsPermanent = Value
        End Set
    End Property
    Private m_IsPermanent As Boolean
    ' Employee can belong to multiple departments
    Public Property Departments() As List(Of String)
        Get
            Return m_Departments
        End Get
        Set
            m_Departments = Value
        End Set
    End Property
    Private m_Departments As List(Of String)
End Class

End Module
answer May 26, 2016 by Shivaranjini

Your answer

Preview

Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...