正在分析JSON:响应中的括号



我想解析YouTube最近发布的这个JSON。这就是我获得视频标题的方式:

NSString *response = [request responseString];
    responseDict = [response JSONValue];
videoTitleArray = [responseDict valueForKeyPath:@"feed.entry.title.$t"];

它就像我想要的那样工作。但我也想展示视频的作者。但以下代码无法正常工作:

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

我得到的作者列表如下:

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

例如,由于括号的原因,我无法在表视图中显示名称。如何像视频标题一样显示作者姓名?

当你看到一个作者时,你会看到这个:

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

这意味着:author是一个author对象数组

每个author对象都有:name对象、uri对象和yt$userId对象

上面描述的每个对象都是NSDictionary

格式化我们有:

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

因此,如果您有videoAuthorArray,则每个元素都是NSDictionary,并具有以下密钥:nameuriyt$userId

每个对象都有一个带有单个键的NSDictionary$t开关的值为

最新更新