NSData dataWithContentsOfFile returning null

前端 未结 6 960
再見小時候
再見小時候 2021-02-19 11:19

I am trying to fetching a JSON file which exist in my xcode resources using this code

-(void)readJsonFiles
{
    NSString *str=[[[NSBu         


        
6条回答
  •  不知归路
    2021-02-19 11:38

    Instead of appending the path, use pathForResource:ofType:, so

    NSString *str=[[NSBundle mainBundle] pathForResource:@"classes" ofType:@"json"];
    
    NSData *fileData = [NSData dataWithContentsOfFile:str];
    

提交回复
热议问题