2

我目前有一个如下所示的 JSON API:

{
  "posts": [
    {
      "id": 277,
      "title": "test title",
      "content": "test content",
      "attachments": [
        {
          "url": "http:\/\/www.example.com\/bar-icon-help@2x.png"
        }
    }
}    

我正在尝试使用“附件”下的“url”。请看看我做错了什么:

-(void)dataRequestCompletedWithJsonObject.(id)jsonObject
{
    NSDictionary *recipeDictionary = (NSDictionary*)jsonObject;

    NSArray* recipeArray = (NSArray*)[recipeDictionary objectForKey:@"posts"];

    self.recipes = [[NSMutableArray alloc] init];

    for (NSDictionary* dic in recipeArray) {

        Recipe *recipe = [[Recipe alloc] init];

        recipe.name = [dic objectForKey:@"title"];
        recipe.thumbNail = [[dic objectForKey:@"attachements"]objectForKey:@"url"];
        recipe.twitterShareCount = [[dic objectForKey:@"id"] intValue];

        [recipes addObject:recipe];
    }

主要是想弄清楚我应该使用什么来代替这一行:

recipe.thumbNail = [[dic objectForKey:@"attachements"]objectForKey:@"url"];

感谢任何帮助的人!

4

1 回答 1

1

您在附件对象中有一组字典。

[[[dic objectForKey:@"attachements"] objectAtIndex:0] objectForKey:@"url"]
于 2012-10-21T21:43:20.443 回答