KkMIW
KkMIW

Reputation: 1112

Add NSDictionary items to NSMutableAray

How to insert NSDictionary items to NSMutableAray and get there count.

- (void)viewDidLoad{

    storeList = [[NSMutableArray alloc] init];
        SBJsonParser *parser = [[SBJsonParser alloc] init];
    NSDictionary *jsonObject = [parser objectWithString:strResponseData error:NULL];
    NSArray *list = [jsonObject objectForKey:@"NAME"];
    for (NSDictionary *lesson in list){
        [listArray addObject:[lesson objectForKey:@"VALUE"]];
    }
    NSLog(@"Count %d",[listArray count]);
}

Crash Log

***** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' * First throw call stack:**

The above code i have done its crashes for me.

Upvotes: 0

Views: 43

Answers (1)

Adis
Adis

Reputation: 4552

The issue is not being unable to store an NSDictionary into the array, but rather, inserting an object that is nil.

Your parsing either didn't pass at some point, or you didn't get the objects you expected, so I'd put some breakpoints and check what the objects you're working are really, and what is stored inside.

Additionally, you haven't initialized your listArray anywhere, and that might be another issue as well.

Upvotes: 1

Related Questions