【发布时间】:2011-07-01 08:09:32
【问题描述】:
在将JSON 转换为NSDictionary 后,我得到了这样的NSDictionary:
content=(
{}
)
content=(
{}
)
content=(
{}
)
我想在每个“内容”字段中获取数据,但我发现无论我做什么(通过使用所有键、objectforkey、keynumerator)Xcode 总是告诉我terminating app due to uncaught exception '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 找到了解决方案。
【问题讨论】:
-
看起来你的 NSDictionary 不是你想象的那样。您的解析和分配可能有问题。您需要重写您的问题,并包含一些代码。
-
我需要先查看一些代码才能确定,但如果这些是您的日志消息,这看起来像
NSArray中的NSDictionary。虽然没有额外的代码,但不能说更多。 -
那不是 Objective-C 代码。但如果您自己找到了答案,请关闭此问题。
-
以后,当您想询问异常时,您需要在问题中包含实际的异常消息,复制并粘贴(不要总结)。此外,当您自己找到解决方案时,请将其发布在答案中,而不是将其编辑到您的问题中。
标签: iphone cocoa json nsdictionary