带有一些重复键的 NSDictionary
将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是对象的“描述”转储。你得到的是一个字典(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".