我正在运行一个ionic
项目的 ios构建app.xcproj
。xcode
我正在从以下位置的服务器下载 json 文件:/var/mobile/Containers/Data/Application/63E66EE9-9A1B-4D4D-AEF6-F8C54D159ED0/Library/NoCloud/MyApp/Timing/DTS.json
并且我通过打印检查了我有文件:
NSURL *urlDTS = [NSURL fileURLWithPath: DTS_Path];
NSString *fileContentDTS = [NSString stringWithContentsOfURL:urlDTS encoding:NSUTF8StringEncoding error:nil];
NSLog(@"Json data is here of DTS %@", fileContentDTS);
这可以打印整个文件,之后当我获得进一步操作的资源路径时,它会显示null
NSString *filePathDTS = [[NSBundle mainBundle] pathForResource:getParameterDTSValueName ofType:@"json"];
NSLog(@"This is the dts path %@", filePathDTS);
即使我已将文件位置检索为/var/mobile/Containers/Data/Application/63E66EE9-9A1B-4D4D-AEF6-F8C54D159ED0/Documents/DTS.json
通过以下链接:
NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *tileDirectory = [documentdir stringByAppendingPathComponent:@"xxxx/DTS"];
NSLog(@"Tile Directory: %@", tileDirectory);
更新
这是文件包含的内容:[{"value":0}]
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)
请指导我如何通过在主包中提供资源来从 json 文件中检索数据???因为它显示为空。