我正在尝试使用此代码获取JSON存在于我的xcode资源中的文件
-(void)readJsonFiles
{
NSString *str=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"classes.json"];
NSLog(@"Path: %@", str);
NSData *fileData = [NSData dataWithContentsOfFile:str];
NSLog(@"Data: %@", fileData);
SBJsonParser *parser = [[SBJsonParser alloc] init] ;
NSDictionary *jsonObject = [parser objectWithData:fileData];
NSLog(@"%@", jsonObject);
}
Run Code Online (Sandbox Code Playgroud)
path返回文件路径的这个链接
/Users/astutesol/Library/Application Support/iPhone Simulator/6.0/Applications/A4E1145C-500C-4570-AF31-9E614FDEADE4/The Gym Factory.app/classes.json
Run Code Online (Sandbox Code Playgroud)
但是当我登录时fileData它会归还给我null.我不知道我在哪里做错了.
我正在实现tableview,我想在tableview的部分显示类名,我试图从使用核心数据实现的数据库中获取类值,我想在classname上使用group by子句获取数据这是我的代码
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
//create managed object context
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSFetchRequest* fetch = [NSFetchRequest fetchRequestWithEntityName:@"Boking_Detail"];
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Boking_Detail"
inManagedObjectContext:context];
NSAttributeDescription* clsName = [entity.attributesByName objectForKey:@"classname"];
NSAttributeDescription* clsDate = [entity.attributesByName objectForKey:@"classdate"];
NSAttributeDescription* startTime = [entity.attributesByName objectForKey:@"starttime"];
NSAttributeDescription* endTime = [entity.attributesByName objectForKey:@"endtime"];
NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
[expressionDescription setName: @"count"];
// [expressionDescription setExpression: countExpression];
[expressionDescription setExpressionResultType: NSInteger32AttributeType];
[fetch setPropertiesToFetch:[NSArray arrayWithObjects:clsName,clsDate,startTime,endTime, expressionDescription, nil]];
[fetch setPropertiesToGroupBy:[NSArray arrayWithObject:clsName]];
[fetch setResultType:NSDictionaryResultType];
NSError* error = nil;
NSArray *results …Run Code Online (Sandbox Code Playgroud)