如何在 VB.NET 中读取 JSON 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37766725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:56:03 来源:igfitidea点击:
How to read JSON file in VB.NET
提问by a.Gurlyeno
I have a JSON file:
我有一个 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"
}
}
]
}
and i want to get this info, like this:
我想得到这个信息,就像这样:
label1.text = "Rap GOD"
label2.text = "122255 likes"
how do i do it?
我该怎么做?
回答by Raktim Biswas
Here's what you can do...
这是你可以做的...
- Firstly, download the JSON Framework
- Add the reference to your Project by Right-clickingon your Projectand Add Reference
- Then, Browse
Newtonsoft.Json.dll(extract the library which you downloaded in step 1)and add the reference from the Reference ManagerWindow.
- 首先,下载JSON框架
- 通过右键单击您的项目并添加引用来添加对您的项目的引用
- 然后,浏览
Newtonsoft.Json.dll(提取您在步骤 1 中下载的库)并从参考管理器窗口添加参考。
Add this code:
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
添加此代码:
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
And, here's the expected output:
而且,这是预期的输出:
And, I hope this above code helps. Now, you can easily read any JSONFile using VB.NET.
而且,我希望上面的代码有帮助。现在,您可以使用VB.NET轻松读取任何JSON文件。
回答by ???? ????? ???? ??????
Imports System.IO
Dim bowerjson As String = File.ReadAllText(HttpContext.Current.Server.MapPath("~/bower.json"))
Diagnostics.Debug.WriteLine(bowerjson)


