我目前有一个JSON API,如下所示:
{
"posts": [
{
"id": 277,
"title": "test title",
"content": "test content",
"attachments": [
{
"url": "http:\/\/www.example.com\/bar-icon-help@2x.png"
}
}
}
我正在尝试使用“附件”下的“网址”。请看看我做错了什么:
-(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"];
感谢任何帮助过的人!
答案 0 :(得分:1)
附件对象中有一系列dicts。
[[[dic objectForKey:@"attachements"] objectAtIndex:0] objectForKey:@"url"]