使用 VB.NET 和 Newtonsoft 解析 JSON 文件中的所有信息

Parse ALL info in JSON file using VB.NET and Newtonsoft

正在尝试了解如何将 Newtonsoft 与 VB.net 一起使用。我正在解析各种信息,很想知道如何将它们全部分开。

这是我的代码:

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

如您所见,我已经能够解析对象 nameage 但不能解析数组 scores 和具有多个值的对象 final.

如有任何帮助,我们将不胜感激,谢谢!

你需要这个class信息

 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