NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSArray* users = [json objectForKey:@"Users"];
NSEnumerator* enumerator = [users objectEnumerator];
id element;
NSMutableArray *results;
Result *fetchedResults;
while(element = [enumerator nextObject]) {
// fetchedResults = [[Result alloc] init]; // i have tried commenting/uncommenting
fetchedResults.name = (NSString *)[[element objectForKey:@"User"] objectForKey:@"name"];
fetchedResults.email = (NSString *)[[element objectForKey:@"User"] objectForKey:@"name"];
NSLog(@"%@", fetchedResults.name);
[results addObject:fetchedResults];
NSLog(@"%@", (NSString *)[[element objectForKey:@"User"] objectForKey:@"name"]); // this returns valid dump
}
NSLog(@"%d", [results count]); // returns 0
我不明白这里有什么问题。我搜索了许多教程和资源,似乎没有发现这里有什么问题。
编辑:
NSLog(@"%@", fetchedResults.name); // dumps null