所以在一个块中我得到并解析一个看起来像这样的JSON对象(任何时候你看到"< ...>"假设正确形成的数据)(这也只是一个)有问题的对象):
{
asset = {
<...>
};
<...>
sections = (
{
<...>
fields = (
);
items = (
);
},
{
<...>
fields = (
);
items = (
);
},
{
<...>
fields = (
);
items = (
{
<...>
properties = {
title = "We welcome guests...";
};
},
{
<...>
properties = {
title = "More text";
};
},
{
<...>
properties = {
title = "Opportunity Insert...";
};
}
);
},
{
<...>
fields = (
{
<...>
values = (
Private,
Public
);
},
{
<...>
values = (
);
},
{
<...>
values = (
);
}
);
items = (
);
},
{
<...>
fields = (
{
<...>
values = (
);
},
{
<...>
values = (
);
}
);
items = (
);
}
);
}
获得此代码的代码(使用AFNetworking):
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:AppsURL([[NSUserDefaults standardUserDefaults] objectForKey:kAuthToken])]];
AFHTTPRequestOperation* op = [[AFHTTPRequestOperation alloc] initWithRequest:req];
[op setResponseSerializer:[[AFJSONResponseSerializer alloc] init]];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (responseObject != nil&&[responseObject isKindOfClass:[NSDictionary class]]) {
NSDictionary* dict = (NSDictionary*)responseObject;
if (dict[@"apps"]&&[dict[@"apps"] isKindOfClass:[NSArray class]]) {
apps = dict[@"apps"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
return;
}
}
NSLog(@"Error Loading apps:%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error:%@",error);
NSLog(@"Response:%@",operation.response.description);
}];
[op start];
此时一切都在加载到内存中并且工作正常。我将其设置为类级NSArray,然后使用该NSArray填充表。当用户从表中选择一个项目后尝试检索数据时,问题就出现了。然后我使用索引并从NSArray中拉出该对象以找到看起来像这样的东西(注意所有项目和字段数组现在都是空的):
{
asset = {
<...>
};
<...>
sections = (
{
<...>
fields = (
);
items = (
);
},
{
<...>
fields = (
);
items = (
);
},
{
<...>
fields = (
);
items = (
);
},
{
<...>
fields = (
);
items = (
);
}
);
}
选择代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row < apps.count) {
//the output of this is what I copy and pasted
NSLog(@"app data to be cleaned up:%@ \r app data sent:%@",apps[indexPath.row],((NSDictionary*)apps[indexPath.row]).mutableCopy);
//I originally thought the problem was here, but the output above proved me wrong
NSMutableDictionary *app = [Functions recurseDictionaryForNull:((NSDictionary*)apps[indexPath.row]).mutableCopy];
[[NSUserDefaults standardUserDefaults] setObject:app
forKey:@"app"];
MainMenuViewController* mainMenu = (MainMenuViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"mainMenu"];
[self.navigationController setViewControllers:@[mainMenu] animated:YES];// reset nav stack
}
}
我有点失败......任何想法可以做到这一点以及如何解决它?
答案 0 :(得分:0)
这是来自服务器的数据。我被告知2“应用程序”是相同的,除了一个项目,结果他们也缺少所有的字段和项目。感谢迪马和迈克不管怎样的时间!