ios – Parse JSON file from URL and return single String

0
50


I am trying to return videoId from the json file at this JSON file from a URL

{
  "kind": "youtube#searchListResponse",
  "etag": "imd66saJvwX2R_yqJNpiIg-yJF8",
  "regionCode": "US",
  "pageInfo": {
    "totalResults": 1,
    "resultsPerPage": 1
  },
  "items": [
    {
      "kind": "youtube#searchResult",
      "etag": "BeIXYopOmOl2niJ3NJzUbdlqSA4",
      "id": {
        "kind": "youtube#video",
        "videoId": "1q7NUPF6j8c"
      },

(Correct return in the example is 1q7NUPF6j8c). I would then like to load the video id in
a

[self.playerView loadWithVideoId:@"the JSON video ID"];

So far I can return the entire JSON to the log with

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:[NSURL URLWithString:@"https://i-doser.com/radio/livestream.json"]
          completionHandler:^(NSData *data,
                              NSURLResponse *response,
                              NSError *error) {
    NSArray* json = [NSJSONSerialization JSONObjectWithData:data
                                                    options:0
                                                      error:nil];
    NSLog(@"YouTube ID: %@", json);
    //NSArray *videoid = [json valueForKeyPath:@"items.0.id.videoId"];
    //NSLog(@"VideoID: %@", videoid);

  }] resume];

I have tried this as a shot in the dark.

//NSArray *videoid = [json valueForKeyPath:@"items.0.id.videoId"];
//NSLog(@"VideoID: %@", videoid);

But that returns nul.

So my question is: How can I return just the videoID and pass it to the self.playerView loadWithVideoId