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

attachments オブジェクトに辞書の配列があります。

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