我有一个JSON文件:
{
"items": [
{
"id": "HkWO1yuYnLU",
"snippet": {
"channelId": "UCR5wZcXtOUka8jTA57flzMg",
"title": "İlyas Yalçıntaş - İçimdeki Duman",
"categoryId": "10"
},
"statistics": {
"viewCount": "37266431",
"likeCount": "122255",
"dislikeCount": "4472",
"favoriteCount": "0",
"commentCount": "7151"
}
}
]
}
我希望得到这样的信息,如下:
label1.text = "Rap GOD"
label2.text = "122255 likes"
我该怎么办?
答案 0 :(得分:1)
这是你可以做的......
Newtonsoft.Json.dll
(提取您在第1步>中下载的库)并添加参考管理器窗口。添加此代码:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim json As String = "{""name"":""Rap God"",""statistics"":{""likeCount"":""122255"",""dislikeCount"":""4472""}}"
Dim read = Newtonsoft.Json.Linq.JObject.Parse(json)
TextBox1.Text = read.Item("name").ToString
TextBox2.Text = read.Item("statistics")("likeCount").ToString + " " + " times"
End Sub
End Class
而且,这是预期的输出:
而且,我希望以上代码有所帮助。现在,您可以使用 VB.NET 轻松阅读任何 JSON 文件。
答案 1 :(得分:0)
Imports System.IO
Dim bowerjson As String = File.ReadAllText(HttpContext.Current.Server.MapPath("~/bower.json"))
Diagnostics.Debug.WriteLine(bowerjson)