ios - 如何从 NSDictionary 中删除空值

标签 ios objective-c swift dictionary nsdictionary

我有一个 JSON 提要:

{
    "count1" = 2;
    "count2" = 2;
    idval = 40;
    level = "<null>";
    "logo_url" = "/assets/logos/default_logo_medium.png";
    name = "Golf Club";
    "role_in_club" = Admin;
}

问题是 "<null>" .在将它保存到 NSUserDefaults 之前,我不知道如何将它从 NSDictionary 中删除。

最佳答案

另一种变体,没有(明确的)循环:

NSMutableDictionary *dict = [yourDictionary mutableCopy];
NSArray *keysForNullValues = [dict allKeysForObject:[NSNull null]];
[dict removeObjectsForKeys:keysForNullValues];

关于ios - 如何从 NSDictionary 中删除空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14148209/

相关文章:

ios - 通过 iOS 上的默认信使向用户选择的收件人发送短信

iphone - iCloud 基础知识和代码示例

ios - 更新到 Xcode 9 有错误

objective-c - WKWebView - 替换网络操作

iphone - iOS:如何访问 `UIKeyboard`?

ios - 速度 slider 问题 - 鼓音序器 Obj - C

ios - 如何更改 userInterfaceLayoutDirection

ios - 将 textField 更改为 textView 时出现问题?

ios - 使用 UINavigationController 在 UIPageViewController 中下推内容

swift - SpriteKit 场景节点比例说明