【发布时间】:2017-09-18 14:42:25
【问题描述】:
这是一个深度嵌套的 JSON,我正在尝试将其解析并创建为模型对象。
基本上我需要创建模型对象,直到 'Child' 数组有 0 个元素。
这是在做什么
dictTree = [dict[@"jsonTree"] mutableCopy];
NSMutableArray *children = [[NSMutableArray alloc] init];
if (dictTree.count > 0)
{
while (true)
{
CategoryChild *categoryChild = [[CategoryChild alloc]init];
NSString *str = dictTree[@"id"];
categoryChild.childId = str;
categoryChild.name = dictTree[@"name"];
categoryChild.type = dictTree[@"type"];
categoryChild.parent = dictTree[@"parent"];
categoryChild.symbol = dictTree[@"symbol"];
categoryChild.multiple = dictTree[@"multiple"];
categoryChild.metricUnit = dictTree[@"metricUnit"];
[children addObject:categoryChild];
dictTree = [dictTree[@"child"] mutableCopy];
if (dictTree.count == 0)
{
break;
}
}
categoryItem.children = children;
[categoryList addObject:categoryItem];
}
不幸的是,在我访问 dictTree[@"id"] 的第二次迭代中 - 崩溃了
'NSInvalidArgumentException',原因:'-[__NSArrayM objectForKeyedSubscript:]:无法识别的选择器发送到实例
问题似乎在于将字典分配给“子”字典并且它似乎确实喜欢它。
虽然在调试器中,我可以看到子值。
任何关于如何处理事情或做错什么的想法都将不胜感激。谢谢。
【问题讨论】:
-
用代码而不是图像编辑问题。
标签: objective-c json nsdictionary