我已经在我的应用程序文件夹中下载了 json 文件,我想从我的应用程序文件夹中读取这些文件以打印特定值。
文件的位置如下:/var/mobile/Containers/Data/Application/63E66EE9-9A1B-4D4D-AEF6-F8C54D159ED0/Library/NoCloud/MyApp/MyFolder/DTS.json
这是文件包含的内容: [{"value":0}] 但是文件内容是在控制台中读取和打印的,正如我在下面提到的但是当我读取特定值时它给出 null
NSURL *libraryDirURL = [[NSFileManager.defaultManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *urlDTSK = [libraryDirURL URLByAppendingPathComponent:@"NoCloud/MyApp/MyFolder/DTS.json"];
NSString *filePathDTS = [NSString stringWithContentsOfURL:urlDTSK encoding:NSUTF8StringEncoding error:nil];
NSLog(@"This is Dts PATH %@", filePathDTS);
NSData *dataDTS = [NSData dataWithContentsOfFile:filePathDTS];
NSLog(@"here is DTS data %@", dataDTS); //this shows null
NSDictionary *jsonDTS = [NSJSONSerialization JSONObjectWithData:dataDTS options:kNilOptions error:nil];
NSLog(@"here is jason DTS %@", jsonDTS);
NSMutableArray *DTSvalue = [jsonDTS valueForKeyPath: @"Value"];
DTSValueIs = DTSvalue[0];
NSLog(@"here is DTS Value first%@", DTSvalue[0]);
NSLog(@"here is DTS value is%@", DTSValueIs);
由此可见This is Dts contents [{"value":0}]
2018-06-11 17:04:40.940006+0500 Muslims 365[3356:819935] here is DTS data (null)