(NET) NET (2014)

Parse Yotube response by Newtonsoft.Json


If you receive JSON from Google.debeloper API and want to process it, for example like this //www.vb-net.com/video/, this need only couple of string of code:



   1:  'https://www.newtonsoft.com/ , Install-Package Newtonsoft.Json 
   2:   
   3:  Imports Newtonsoft.Json.Linq
   4:  Imports System.IO
   5:   
   6:  Module Module1
   7:   
   8:      Sub Main()
   9:          Dim YoutubeJson As JObject = JObject.Parse(File.ReadAllText("Youtube.Json"))
  10:          Dim MyLastVideoArr As JArray = YoutubeJson("items")
  11:          '
  12:          Dim Template As String = "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td><a href='https://www.youtube.com/watch?v={2}'>{3}</a></td><td>Ukraine</td></tr>" & vbCrLf
  13:          Dim Str1 As New Text.StringBuilder
  14:          For I As Integer = 0 To MyLastVideoArr.Count - 1
  15:              Str1.AppendFormat(Template,
  16:                                827 + MyLastVideoArr.Count - I - 21,
  17:                                DateTime.Parse(MyLastVideoArr(I)("snippet")("publishedAt").Value(Of String)).ToString("dd/MM/yyyy"),
  18:                                MyLastVideoArr(I)("snippet")("resourceId")("videoId").Value(Of String),
  19:                                MyLastVideoArr(I)("snippet")("title").Value(Of String))
  20:   
  21:          Next
  22:          Debug.Print(Str1.ToString)
  23:      End Sub
  24:  End Module
  25:   
  26:  'curl \
  27:  '  'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UUDxUCKh5eNy9iYYm3Slydzw&key=[YOUR_API_KEY]' \
  28:  '  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  29:  '  --header 'Accept: application/json' \
  30:  '  --compressed
  31:   
  32:  'Get https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UUDxUCKh5eNy9iYYm3Slydzw&key=[YOUR_API_KEY] HTTP/1.1
  33:  'Authorization: Bearer [YOUR_ACCESS_TOKEN]
  34:  'Accept: application/ json
  35:   

And this a example result of JSON of Google.developer API.



More example of using Google API



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/ParseYoutubeJson/Index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>