相关疑难解决方法(0)

在嵌套的NSDictionary中替换NSNull的出现次数

这个问题类似于这个问题,但这种方法只适用于字典的根目录下.

我想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)

replace nsdictionary plist ios nsnull

9
推荐指数
2
解决办法
6441
查看次数

将NSNull对象分配给NSString

我正在编写一个iOS应用程序,我需要通过Azure上的移动服务从SQL数据库中获取数据.

下载数据后,我得到了一个NSDictionary包含SQL-Table的所有属性.如果属性为空,则值为NSNull.

有没有一种方法可以NSNullNSString没有IF语句的情况下传递给我(我不希望有20个if语句......)?

nsstring ios nsnull

0
推荐指数
1
解决办法
1358
查看次数

标签 统计

ios ×2

nsnull ×2

nsdictionary ×1

nsstring ×1

plist ×1

replace ×1