Deserializing JSON in Visual basic

前端 未结 4 583
北荒
北荒 2020-11-29 10:26

Basically, I\'m trying to parse the comments from a 4chan thread using the 4chan JSON API. https://github.com/4chan/4chan-API

basically, there is one rich text box c

4条回答
  •  一整个雨季
    2020-11-29 10:58

    Note:

    First you have to install Newtonsoft.Json on nuget console. Then include following code on top of your code.

     Imports Newtonsoft.Json
    

    Step:1 Create class with get & set properties.

    Public Class Student
    
    Public Property rno() As String
        Get
            Return m_rno
        End Get
        Set(value As String)
            m_rno = value
        End Set
    End Property
    Private m_rno As String
    Public Property name() As String
        Get
            Return m_name
        End Get
        Set(value As String)
            m_name = value
        End Set
    End Property
    Private m_name As String
    Public Property stdsec() As String
        Get
            Return m_StdSec
        End Get
        Set(value As String)
            m_StdSec = value
        End Set
    End Property
    Private m_stdsec As String
    
    End Class
    

    Step: 2 Create string as a json format and conver as a json object model.

     Dim json As String = "{'rno':'09MCA08','name':'Kannadasan Karuppaiah','stdsec':'MCA'}"
    
     Dim stuObj As Student = JsonConvert.DeserializeObject(Of Student)(json)
    

    Step: 3 Just traverses by object.entity name as follows.

    MsgBox(stuObj.rno)
    MsgBox(stuObj.name)
    MsgBox(stuObj.stdsec)
    

提交回复
热议问题