NSData dataWithContentsOfFile returning null

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

    It's failed to read your file for some reason. Use -dataWithContentsOfFile:options:error: to find out why.

    NSError* error = nil;
    NSData *fileData = [NSData dataWithContentsOfFile:str options: 0 error: &error];
    if (fileData == nil)
    {
       NSLog(@"Failed to read file, error %@", error);
    }
    else
    {
        // parse the JSON etc
    }
    

提交回复
热议问题