带有一些重复键的 NSDictionary

发布于 2024-11-17 22:23:35 字数 2058 浏览 1 评论 0原文

JSON 转换为 NSDictionary 后,我得到了这样的 NSDictionary

content=(
     {}
         )
content=(
     {}
         )
content=(
     {}
         )

我想在每个“内容”字段中获取数据,但我发现了任何东西我确实(通过使用所有键、objectforkey、keynumerator),Xcode 总是告诉我由于未捕获的异常“NSInvalidArgumentException”而终止应用程序。我认为创建一个带有重复键的 nsdictionary 是不合理的,但我需要解决我的项目中的问题。

代码:

{
    "adv_name" = "\U767d\U677f";
    page =     (
                {
            content =             (
                                {
                    content = "";
                    type = "\U56fe\U7247";
                },
                                {
                    content = 3;
                    type = "\U6587\U5b57";
                },
                                {
                    content = "";
                    type = "\U89c6\U9891";
                }
            );
            "content_count" = 3;
        },
                {
            content =             (
                                {
                    content = "";
                    type = "\U56fe\U7247";
                },
                                {
                    content = 2;
                    type = "\U6587\U5b57";
                },
                                {
                    content = "";
                    type = "\U89c6\U9891";
                }
            );
            "content_count" = 3;
        },
                {
            content =             (
                                {
                    content = "";
                    type = "\U56fe\U7247";
                },
                                {
                    content = "";
                    type = "\U89c6\U9891";
                },
                                {
                    content = 12;
                    type = "\U6587\U5b57";
                }
            );
            "content_count" = 3;
        }
    );
    "page_count" = 3;
}

我使用 objectEnumerator 找到了解决方案。

I got a NSDictionary like this after convert JSON to NSDictionary:

content=(
     {}
         )
content=(
     {}
         )
content=(
     {}
         )

I want to pick up data in each 'content' field, but I found whatever I did (by using all keys, objectforkey, keynumerator) the Xcode always told me terminating app due to uncaught exception 'NSInvalidArgumentException'. I think it's not reasonable to create a nsdictionary with repeat keys,but i need to solve the problem in my project.

the code:

{
    "adv_name" = "\U767d\U677f";
    page =     (
                {
            content =             (
                                {
                    content = "";
                    type = "\U56fe\U7247";
                },
                                {
                    content = 3;
                    type = "\U6587\U5b57";
                },
                                {
                    content = "";
                    type = "\U89c6\U9891";
                }
            );
            "content_count" = 3;
        },
                {
            content =             (
                                {
                    content = "";
                    type = "\U56fe\U7247";
                },
                                {
                    content = 2;
                    type = "\U6587\U5b57";
                },
                                {
                    content = "";
                    type = "\U89c6\U9891";
                }
            );
            "content_count" = 3;
        },
                {
            content =             (
                                {
                    content = "";
                    type = "\U56fe\U7247";
                },
                                {
                    content = "";
                    type = "\U89c6\U9891";
                },
                                {
                    content = 12;
                    type = "\U6587\U5b57";
                }
            );
            "content_count" = 3;
        }
    );
    "page_count" = 3;
}

I've found the solution using objectEnumerator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的新欢旧爱 2024-11-24 22:23:35

我认为这是对象的“描述”转储。你得到的是一个字典(NSDictionary),其中包含条目“adv_name”、“page”和“page_count”。

字典条目“page”包含 3 个字典的数组 (NSArray)。

3 个字典中的每一个都在“内容”条目中包含另外 3 个字典的数组。

最里面的字典包含条目“内容”和“类型”。

I presume this is a "description" dump of the object. What you've got is a dictionary (NSDictionary) containing entries "adv_name", "page", and "page_count".

The dictionary entry "page" contains an array (NSArray) of 3 dictionaries.

Each of the 3 dictionaries contains an array of 3 more dictionaries in the "content" entry.

The innermost dictionaries contain entries "content" and "type".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文