試圖弄清楚如何在 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
如您所見,我已經能夠決議物件名稱和年齡,但不能決議陣列分數和具有多個值的物件final。
對此的任何幫助將不勝感激,謝謝!
uj5u.com熱心網友回復:
你需要這個類資訊
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/484528.html