この問題は RestKit だけに限定されているとは思いません。JSONを提供しているサーバーからの詳細。私は AFNetworking を使用して同じ問題を抱えています。
Null を削除して空の文字列に置き換えるために使用できる、この Dictionary カテゴリを見つけました。それを使用するか、単にロジックを取り出して null 値を並べ替えることができます。
@implementation NSDictionary (JRAdditions)
- (NSDictionary *) dictionaryByReplacingNullsWithStrings {
NSMutableDictionary *replaced = [NSMutableDictionary dictionaryWithDictionary:self];
const id nul = [NSNull null];
const NSString *blank = @"";
for(NSString *key in self) {
const id object = [self objectForKey:key];
if(object == nul) {
//pointer comparison is way faster than -isKindOfClass:
//since [NSNull null] is a singleton, they'll all point to the same
//location in memory.
[replaced setObject:blank forKey:key];
}
}
return [NSDictionary dictionaryWithDictionary:replaced];
}
+ (NSDictionary *)dictionaryByReplacingNullsWithStrings:(NSDictionary *)dict {
NSMutableDictionary *replaced = [NSMutableDictionary dictionaryWithDictionary:dict];
const id nul = [NSNull null];
const NSString *blank = @"";
for(NSString *key in dict) {
const id object = [dict objectForKey:key];
if(object == nul) {
//pointer comparison is way faster than -isKindOfClass:
//since [NSNull null] is a singleton, they'll all point to the same
//location in memory.
[replaced setObject:blank forKey:key];
}
}
return [NSDictionary dictionaryWithDictionary:replaced];
}
@end
// you can use this category on your dictionaries.
NSDictionary *jsonDict = JSON;
jsondict = [jsonDict dictionaryByReplacingNullsWithStrings];