Home > Software engineering >  Parse ALL info in JSON file using VB.NET and Newtonsoft
Parse ALL info in JSON file using VB.NET and Newtonsoft

Time:05-30

Trying to figure out how to use Newtonsoft with VB.net. I'm parsing a variety of information and would love to know how to separate it all.

Here's my code:

Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

Public Module Module1

    Public Sub Main()
        Dim json As String = "{""name"":""Sam"",""age"":""23"",""scores"":[{""main"":12,""side"":40},{""main"":123,""side"":51}],""final"":{""test1"":0,""test2"":2}}"
        Dim finalInfo = JsonConvert.DeserializeObject(Of information)(json)

        Console.WriteLine(finalInfo.name)

        Console.ReadKey()

    End Sub

    Public Class information
        Public name As String
        Public age As String
    End Class

End Module

As you can see I'm already able to parse objects name and age but not the array scores and the object with multiple values final.

Any help with this would be deeply appreciated, thank you!

CodePudding user response:

you need this class information

 Public Class information
        Public Property name As String
        Public Property age As String
        Public Property scores As Score()
        Public Property final As Final
    End Class

Public Class Score
        Public Property main As Integer
        Public Property side As Integer
    End Class

    Public Class Final
        Public Property test1 As Integer
        Public Property test2 As Integer
    End Class

   
  • Related