troubleshooting Question

vb.net Deserialize JSON output - YouTube API (With somewhat of a working example included)

Avatar of Wayne Barron
Wayne BarronFlag for United States of America asked on
ASP.NETVisual Basic.NETJSON
21 Comments2 Solutions948 ViewsLast Modified:
Hello All;

I had another thread open, but I closed it out and started this one.
With a working example, but need to get all the values, instead of a single value duplicated for the number of records returned.

Here is the test JSON that I am using.
{
 "kind": "youtube#playlistItemListResponse",
 "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/YJYLWeQ7ZaYKr3ce1Z9EIjD9WVU\"",
 "nextPageToken": "CAUQAA",
 "pageInfo": {
  "totalResults": 10,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#playlistItem",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/0TyxpFnbR5GigaSoRo2gAPfUHwE\"",
   "id": "UExDSkxpSjh1U0pyQ3B4d3o0bG1uejFOdnZGMlN6WGJoay41NkI0NEY2RDEwNTU3Q0M2",
   "snippet": {
    "publishedAt": "2014-12-10T21:16:39.000Z",
    "channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
    "title": "Private video",
    "description": "This video is private.",
    "channelTitle": "Late Show with David Letterman",
    "playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
    "position": 0,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "4bVgilYncao"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/PVF3VoVEG0X1jmV6GeUNhpCIzF4\"",
   "id": "UExDSkxpSjh1U0pyQ3B4d3o0bG1uejFOdnZGMlN6WGJoay4yODlGNEE0NkRGMEEzMEQy",
   "snippet": {
    "publishedAt": "2014-12-10T21:16:58.000Z",
    "channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
    "title": "Private video",
    "description": "This video is private.",
    "channelTitle": "Late Show with David Letterman",
    "playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
    "position": 1,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "H9eYkpgeeI8"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/BLUJWU0eHjBeEizXySdnzUhi2lQ\"",
   "id": "UExDSkxpSjh1U0pyQ3B4d3o0bG1uejFOdnZGMlN6WGJoay4wMTcyMDhGQUE4NTIzM0Y5",
   "snippet": {
    "publishedAt": "2014-12-10T21:17:14.000Z",
    "channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
    "title": "Private video",
    "description": "This video is private.",
    "channelTitle": "Late Show with David Letterman",
    "playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
    "position": 2,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "ONgN2Hgz3XE"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/qlX2iXH1WPg7D3-eq7jInjQyj2c\"",
   "id": "UExDSkxpSjh1U0pyQ3B4d3o0bG1uejFOdnZGMlN6WGJoay41MjE1MkI0OTQ2QzJGNzNG",
   "snippet": {
    "publishedAt": "2014-12-10T21:17:30.000Z",
    "channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
    "title": "Private video",
    "description": "This video is private.",
    "channelTitle": "Late Show with David Letterman",
    "playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
    "position": 3,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "1Ee4bfu_t3c"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/698H3tj04Cx7lZ8z4rHjL4DPtUI\"",
   "id": "UExDSkxpSjh1U0pyQ3B4d3o0bG1uejFOdnZGMlN6WGJoay4wOTA3OTZBNzVEMTUzOTMy",
   "snippet": {
    "publishedAt": "2014-12-10T21:17:47.000Z",
    "channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
    "title": "Private video",
    "description": "This video is private.",
    "channelTitle": "Late Show with David Letterman",
    "playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
    "position": 4,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "Bzr5VtFvSyw"
    }
   }
  }
 ]
}

OR (You can use the code below if you have a YouTube API to add to the end of the URL String.)


This is the working code that returns duplicate values.

' Newtonsoft.Json
Dim n As New WebClient()
        Dim jsonString As String = n.DownloadString("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+id&playlistId=PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk&key=YOUR_API_KEY_HERE")

        Dim jo = Newtonsoft.Json.Linq.JObject.Parse(jsonString)
        Dim VidID = jo("items")(0)("snippet")("resourceId")("videoId")
        For Each Row In jo("items") 
            Response.Write(VidID)
        Next

Could someone please assist me in deserialize this?
Thank You
Carrzkiss
ASKER CERTIFIED SOLUTION
it_saige
Developer
Join our community to see this answer!
Unlock 2 Answers and 21 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 21 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros