我有這個代碼NSMutable陣列錯誤
SBJsonParser *vol= [[SBJsonParser alloc]init];
if (body) {
NSArray *feeds = [vol objectWithString:body error:nil];
NSDictionary *results = [body JSONValue];
NSArray *subs = [results valueForKey:@"subscriptions"];
NSArray *list;
NSMutableArray *sub;
for (NSDictionary *iscrizione in subs){
NSLog([iscrizione objectForKey:@"title"]);
NSLog([iscrizione objectForKey:@"htmlUrl"]);
list=[NSArray arrayWithObjects:[iscrizione objectForKey:@"title"], [iscrizione objectForKey:@"htmlUrl"], nil];
[sub addObject:list];
}
但是當我嘗試添加列表中的NSMutableArray程序崩潰。爲什麼? 如何在數據結構中插入[iscrizione objectForKey:@"title"]
和[iscrizione objectForKey:@"htmlUrl"]
?
編輯**
SBJsonParser *vol= [[SBJsonParser alloc]init];
if (body) {
NSArray *feeds = [vol objectWithString:body error:nil];
NSDictionary *results = [body JSONValue];
NSArray *subs = [results valueForKey:@"subscriptions"];
NSMutableArray *sub = [[NSMutableArray alloc] initWithCapacity:[subs count]];
for (NSDictionary *iscrizione in subs){
[sub addObject:iscrizione];
}
NSDictionary *it=[[NSDictionary alloc]initWithDictionary:[sub objectAtIndex:0]];
NSLog([it objectForKey:@"title"]);
}
這是我的代碼。但我不明白爲什麼我不能NSLog [it objectForKey:@「title」]。
請,提供了一種碰撞信息。它會拋出什麼錯誤? –