0
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
我不明白這裏的錯誤。我已經搜索了大量的教程和資源似乎沒有得到什麼錯誤在這裏。如何將自定義NSObject複製到NSMutableArray
編輯:
NSLog(@"%@", fetchedResults.name); // dumps null
我在「id元素」下面有NSMutableArray *結果。不會那樣嗎? –
只需在上面輸入的代碼中添加alloc和init即可。 – btype
它崩潰的應用程序。如果有幫助,我已經啓用了ARC。 –