我從提供程序中得到了以下簡化的JSON字符串,因爲我使用Visual Studio和vb.Net的時間很長,所以我非常生疏!簡單工作VB.net中的json.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,爲什麼沒有其他性質的我類填充,我需要做什麼來解決這個問題,沒有錯誤報告。
我使用這個網站http://jsonutils.com/來自動創建JSON字符串的類來加速一些事情。以爲我會爲別人提到它。 – mikro
在某些ASP.Net工具包中還有一個來自Microsoft IIRC的VS插件,但我忘了名字... – sloth
@mikro,感謝您的鏈接。這將非常方便。謝謝! –