Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3712

Using JavaScript JSON.parse() with nested JSON [duplicate]

$
0
0

I am trying to use the JSON.parse() function in JavaScript to extract the channel name from google API output. This is what I currently have:

function ref() {        var channelID = document.getElementById("ccib").value; // set id        const http = new XMLHttpRequest() // define HTTP        http.open("GET", "https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&id=" + channelID +"&key=API_KEY") // get request        http.send()        http.onload = () => document.getElementById("cname").innerHTML = JSON.parse(http.responseText).items;      }

The problem is google outputs nested JSON: (Output from https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&id=UCF0pVplsI8R5kcAqgtoRqoA&key=API_KEY)

```
{"kind": "youtube#channelListResponse","etag": "zrkZA4ZQYMoECWGgDTOve4IqgZo","pageInfo": {"totalResults": 1,"resultsPerPage": 5      },"items": [        {"kind": "youtube#channel","etag": "h-FGBzbg0msUnPu1s5BN4sjn7FE","id": "UCF0pVplsI8R5kcAqgtoRqoA","brandingSettings": {"channel": {"title": "Popular on YouTube","description": "The pulse of what's popular on YouTube. Check out the latest music videos, trailers, comedy clips, and everything else that people are watching right now.","trackingAnalyticsAccountId": "UA-52627333-1"        },"image": {"bannerExternalUrl": "https://yt3.ggpht.com/SA9KUkktZW3wfGUfDQtlWc7NfLvDyTsBhqTw2USIEIWvOWjiu7K0_CkBE9aahdJfxj62v3g3YQs"        }      }    }  ]}

All I need is the "title" string in the "channel" part.
plz can you write code to do this.
Thanks.

Also, if this helps, I am using the YouTube Data API v3.

Viewing all articles
Browse latest Browse all 3712

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>