这个问题类似于这个问题,但这种方法只适用于字典的根目录下.
我想NSNull用空字符串替换任何出现的值,以便我可以将完整的字典保存到plist文件(如果我用NSNull添加它,文件将不会写入).
但是,我的词典里面嵌套了词典.像这样:
"dictKeyName" = {
innerStrKeyName = "This is a string in a dictionary";
innerNullKeyName = "<null>";
innerDictKeyName = {
"innerDictStrKeyName" = "This is a string in a Dictionary in another Dictionary";
"innerDictNullKeyName" = "<null>";
};
};
Run Code Online (Sandbox Code Playgroud)
如果我使用:
@interface NSDictionary (JRAdditions)
- (NSDictionary *) dictionaryByReplacingNullsWithStrings;
@end
@implementation NSDictionary (JRAdditions)
- (NSDictionary *) dictionaryByReplacingNullsWithStrings {
const NSMutableDictionary *replaced = [NSMutableDictionary dictionaryWithDictionary:self];
const id nul = [NSNull null];
const NSString *blank = @"";
for(NSString *key in replaced) …Run Code Online (Sandbox Code Playgroud) 我正在编写一个iOS应用程序,我需要通过Azure上的移动服务从SQL数据库中获取数据.
下载数据后,我得到了一个NSDictionary包含SQL-Table的所有属性.如果属性为空,则值为NSNull.
有没有一种方法可以NSNull在NSString没有IF语句的情况下传递给我(我不希望有20个if语句......)?