Advertisement
nicksonthc

Read JSON file

Sep 19th, 2018
3,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.01 KB | None | 0 0
  1.    Dim json As String = File.ReadAllText("D:\nic.json")
  2.  
  3.         Dim jsonres = JToken.Parse(json)
  4.  
  5.         'json string with single object
  6.         If TypeOf jsonres.SelectToken("result") Is JObject Then
  7.             lstMsg.Items.Add("Checked JSON type : Token result is an object")
  8.  
  9.             'nested object displayed , our information in token "result"
  10.             Dim obj As JObject = JObject.Parse(json)
  11.             lstMsg.Items.Add("JSON string is " & obj.ToString)
  12.  
  13.             'so at here we get inner object by specified token name "result"
  14.             Dim objResult = obj.SelectToken("result")
  15.  
  16.             'assign to variable
  17.             jName = objResult.SelectToken("Name").ToString
  18.             jData = objResult.SelectToken("Data").ToString
  19.             jDate = objResult.SelectToken("DateTime").ToString
  20.  
  21.             'show at listbox
  22.             lstMsg.Items.Add("Name is :" & jName)
  23.             lstMsg.Items.Add("Data is :" & jData)
  24.             lstMsg.Items.Add("Date is :" & jDate)
  25.         End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement