小编use*_*278的帖子

NSData dataWithContentsOfFile返回null

我正在尝试使用此代码获取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.我不知道我在哪里做错了.

iphone objective-c nsdata ios

13
推荐指数
3
解决办法
3万
查看次数

如何在核心数据中应用group by子句

我正在实现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)

iphone core-data objective-c ios

2
推荐指数
1
解决办法
3355
查看次数

标签 统计

ios ×2

iphone ×2

objective-c ×2

core-data ×1

nsdata ×1