我从一个提供者那里得到了以下简化的 JSON 字符串,自从我使用 Visual Studio 和 vb.Net 以来已经很长时间了,所以我很生疏!
{
"Venue": {
"ID": 3145,
"Name": "Big Venue, Clapton",
"NameWithTown": "Big Venue, Clapton, London",
"NameWithDestination": "Big Venue, Clapton, London",
"ListingType": "A",
"Address": {
"Address1": "Clapton Raod",
"Address2": "",
"Town": "Clapton",
"County": "Greater London",
"Postcode": "PO1 1ST",
"Country": "United Kingdom",
"Region": "Europe"
},
"ResponseStatus": {
"ErrorCode": "200",
"Message": "OK"
}
}
}
我想使用 JSON.Net 将其转换为我可以使用的东西,我已经阅读了示例等,并且 JSON.net 看起来像是答案,但我没有得到任何结果。
我的 .Net 代码(Me.TextBox1.Text 包含上面显示的 JSON)
Imports Newtonsoft.Json
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim obj As JSON_result
obj = JsonConvert.DeserializeObject(Of JSON_result)(Me.TextBox1.Text)
MsgBox(obj.ID)
End Sub
End Class
Public Class JSON_result
Public ID As Integer
Public Name As String
Public NameWithTown As String
Public NameWithDestination As String
Public ListingType As String
End Class
有人可以解释为什么 obj.ID 总是以 0 结束吗?为什么我的类的其他属性都没有被填充,以及我需要做什么来解决这个问题,没有报告错误。