我有一个来自服务提供商的简化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,以及为什么我的类的其他属性都没有被填充,并且我需要做什么来解决这个问题,没有报告任何错误。