6

I have a JSON file:

 {
 "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?

1
  • 4
    Please read How to Ask and also take the Tour. You'll need to deserialize or parse it depending on how much of the info you want Commented Jun 11, 2016 at 17:42

2 Answers 2

11

Here's what you can do...

  1. Firstly, download the JSON Framework
  2. Add the reference to your Project by Right-clicking on your Project and Add Reference
  3. Then, Browse Newtonsoft.Json.dll(extract the library which you downloaded in step 1) and add the reference from the Reference Manager Window.

Reference Manager

  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
    

And, here's the expected output:

Output

And, I hope this above code helps. Now, you can easily read any JSON File using VB.NET.

Sign up to request clarification or add additional context in comments.

1 Comment

huge project. Didnt compile out of the box. Can you make a smaller one?
0
Imports System.IO

Dim bowerjson As String = File.ReadAllText(HttpContext.Current.Server.MapPath("~/bower.json"))
Diagnostics.Debug.WriteLine(bowerjson)

2 Comments

Hi, your answer might be right but please try to explain your code when posting answers
i second ali, please add some explanation to your post. for WindowsForms users, http doesnt make any sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.