我使用以下代码通过coredata访问JSON值,
NSManagedObjectContext *context = [[DataAccessLayer sharedInstance] managedObjectContext];
NSArray *existingResults = [context fetchObjectsForEntityName:NSStringFromClass([Serchtrial class]) withSortColumn:nil withSortDescending:FALSE withPredicate:nil];
NSLog(@"->%@",existingResults);
Serchtrial *result;
for(int i=0;i<[existingResults count];i++)
{
result=[existingResults objectAtIndex:i];
[mydata setValue:result forKey:[NSString stringWithFormat:@"checka%d",i]];
}
NSLog(@"mydata age%@",[mydata objectForKey:@"checka0"]);
日志返回结果如下
mydata age<Serchtrial: 0x8c80a10> (entity: Serchtrial; id: 0x8c81990 <x- coredata://39E99C99-5639-4C67-86D5-D9B97C79EDF2/Serchtrial/p2> ; data: {
age = "18-25";
gender = Female;
keywords = "AB-ve,o+ve";
"trial_Id" = 0;
"trial_desc" = nil;
})
但我只想要单个字典中的数据
data: {
age = "18-25";
gender = Female;
keywords = "AB-ve,o+ve";
"trial_Id" = 0;
"trial_desc" = nil;
}
我应该在代码中做出哪些更改,请帮助解决此问题。
答案 0 :(得分:0)
要使获取请求返回字典而不是管理对象,您必须设置
[request setResultType:NSDictionaryResultType];
代表NSFetchRequest
。