Question

I want to parse this JSON YouTube recently featured. This is how I get the title of the videos:

NSString *response = [request responseString];
    responseDict = [response JSONValue];

videoTitleArray = [responseDict valueForKeyPath:@"feed.entry.title.$t"];

And it works like I want it. But I also want to display the author of the video. But the following code for this does not work properly:

videoAuthorArray = [responseDict valueForKeyPath:@"feed.entry.author.name.$t"];
    NSLog(@"%@", videoAuthorArray);

The list of the authors I get looks like this:

(
    author 1
),
    (
    author 2
),
    (
    author 3
),
    (
    author 4
),

I can't display the names in for example a table view because of the brackets. How can I display the author names like the video titles?

Was it helpful?

Solution

When you see an Author you see this:

"author":[{"name":{"$t":"mls"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/mls"},"yt$userId":{"$t":"SZbXT5TLLW_i-5W8FZpFsg"}}]

this means: author is an array of author objects

each author object has: name object, a uri object and a yt$userId object

each of this objects described above is a NSDictionary

formated we have:

"author":[
  {
    "name": {
      "$t":"mls"
    },
    "uri": {
      "$t":"http://gdata.youtube.com/feeds/api/users/mls"
    },
    "yt$userId":{
      "$t":"SZbXT5TLLW_i-5W8FZpFsg"
    }
  }
],

so if you have your videoAuthorArray each element is an NSDictionary and has this keys: name, uri and yt$userId

each of this objects has an NSDictionary with a single key: $t witch has the value

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top