-(void)writeAllCategoriesInJson:(NSDictionary *)dict
{
NSArray *arry_allCategory = [[NSArray alloc] initWithObjects:dict, nil];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arry_allCategory options:NSJSONWritingPrettyPrinted error:&error];
if (!jsonData && error){
NSLog(@"Error creating JSON: %@", [error localizedDescription]);
return;
}
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// Build the path, and create if needed.
NSString* filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* fileName = @"Categories.json";
NSString* fileAtPath = [filePath stringByAppendingPathComponent:fileName];
if (![[NSFileManager defaultManager] fileExistsAtPath:fileAtPath]) {
[[NSFileManager defaultManager] createFileAtPath:fileAtPath contents:nil attributes:nil];
}
// The main act...
[[jsonString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:fileAtPath atomically:NO];
}
此处应用
崩溃“线程90:EXC_BAD_ACCESS(代码= 1,地址= 0x18)”
在下面的行上:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arry_allCategory options:NSJSONWritingPrettyPrinted error:&error];
此行的问题是什么。它一直运行良好,并且在崩溃之间一直正常运行。我尽力了,但是问题仍然存在。