0

Here's my question:

So when you go to https://www.googleapis.com/youtube/v3/playlists?id=PLEylltUN0Ao6PvGUOJuVOAh6sSQvwoZQ3&key=AIzaSyBr7_g-xlBCBR6Mxk_2P0GRWeM5b_aJ5uM&part=snippet

You get a lot of information but I only want one thing and that is:

at thumbnails then default and then url so how do I do that?

To make it more clear:

"thumbnails": {
 "default": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg",
  "width": 120,
  "height": 90
 },
 "medium": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/mqdefault.jpg",
  "width": 320,
  "height": 180
 },
 "high": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/hqdefault.jpg",
  "width": 480,
  "height": 360
 },
 "standard": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/sddefault.jpg",
  "width": 640,
  "height": 480
 },
 "maxres": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/maxresdefault.jpg",
  "width": 1280,
  "height": 720
 }
},

And then

     "default": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg",
  "width": 120,
  "height": 90
 },

And then

"url": "https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg",

I want to return that url: https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg

I'm coding in C#

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Typically
  • 41
  • 1
  • 8

1 Answers1

1

I had a look on StackOverflow for an answer to your question and found these related questions, which may be helpful for you.

Deserializing JSON using JSon.NET with dynamic data

How to get a json string from url?

The first link describes how to achieve this using either SimpleJSON or Json.NET (http://www.newtonsoft.com/json). The second link describes how to download the JSON you want to parse in C#.

In your case, you would have to change

string title = json.query.pages["6695"].title;

to something like

string url = json["items"][0]["snippet"]["thumbnails"]["default"]["url"];

in order to get the required url (You don't need to bother with the foreach statement). Also, "text" in the line

dynamic json = SimpleJson.DeserializeObject(text)

would have to be replaced with the downloaded JSON (see the second link).

Community
  • 1
  • 1
Thomas
  • 126
  • 5
  • You're getting closer! But json.items[0].snippet.thumbnails.high.url is invalid i get this as error: There is no definition for "items". I guess that means json.items[0] – Typically Jan 30 '16 at 16:15
  • Sorry - I've figured it out and changed my answer accordingly. – Thomas Jan 30 '16 at 17:25