使用vb.net和newtonsoft在JSON文件中解析所有信息

发布于 2025-02-03 03:12:14 字数 787 浏览 3 评论 0原文

试图弄清楚如何与vb.net一起使用newtonsoft。我正在解析各种信息,很想知道如何将所有信息分开。

这是我的代码:

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

如您所见,我已经能够解析对象 name age ,而不是数组得分和具有多个的对象值最终

对此的任何帮助将不胜感激,谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性 2025-02-10 03:12:14

您需要此类信息

 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

   

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

   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文