1
내 NSDictionaries 내의 몇 가지 배열에 null 값이 있으므로이를 통해 실행하고 모든 null 값을 제거하려고합니다. 여기 내 시도입니다.null 값을 제거하는 NSDictionary. JSON 피드에서 생성
newClubs = [newClubs addObject:theclub];
및 루프에 대한이 내 라인
newBadges = [newBadges addObject:thebadge];
모두 :
dict = [dict dictionaryByReplacingNullsWithStrings];
NSMutableDictionary *mdict = [dict mutableCopy];
NSArray *clubs = [dict objectForKey:@"clubs"];
NSArray *badges = [dict objectForKey:@"badges"];
NSMutableArray *newBadges = [badges mutableCopy];
NSMutableArray *newClubs = [clubs mutableCopy];
for(int i = 0; i < [clubs count]-1; i++){
NSDictionary *theclub = [clubs objectAtIndex:i];
theclub = [theclub dictionaryByReplacingNullsWithStrings];
newClubs = [newClubs addObject:theclub];
}
for(int i = 0; i < [badges count]-1; i++){
NSDictionary *thebadge = [clubs objectAtIndex:i];
thebadge = [thebadge dictionaryByReplacingNullsWithStrings];
newBadges = [newBadges addObject:thebadge];
}
[mdict removeObjectForKey:@"badges"];
[mdict removeObjectForKey:@"clubs"];
NSLog(@"new Badges %@", newBadges);
[mdict setObject:newBadges forKey:@"badges"];
[mdict setObject:newClubs forKey:@"clubs"];
문제
내가 코드의 2 개 라인에 오류가 있다는 것입니다.{
"id":249,
"email":"[email protected]",
"full_name":"Some one",
"statement":"Lets kick some robot but. ",
"avatar_url":"http://www.somesite.com/logo.png",
"clubs":
[{"id":31,"name":"Nintendo Games Club","logo_url":"http://www.somesite.com/logo.png","role_in_club":"Admin","level":{"id":23,"name":"Handicap","position":1,"image_url":"http://www.somesite.com/logo.png","code":"","weeks_to_achieve":1,"times_to_achieve":1,"club_type":{"id":13,"type_name":"Golf","token_criteria":false}}}],
"badges":
[{"id":29,"name":"Nearest the pin","description":"","image_url":"http://www.somesite.com/logo.png","club_id":null},{"id":28,"name":"Longest Drive","description":"","image_url":"http://www.somesite.com/logo.png","club_id":null}]
}
감사합니다. :) – jimbob