NSData dataWithContentsOfFile returning null

前端 未结 6 987
再見小時候
再見小時候 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:59

    You can follow this to get NSData from your document directory

    NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
    stringPath  = [stringPath stringByAppendingPathComponent:@"JSON_FILE_NAME.json"];
    NSLog(@"stringpath %@",stringPath);
    NSData *fileData = [NSData dataWithContentsOfFile:stringPath];
    

    Hope this will work for you.

提交回复
热议问题