let docDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .allDomainsMask, true)[0]
let jsonPath = (docDir as NSString).appendingPathComponent( type +".json")
写入
guard let jsondata = jsondata else{
return
}
guard letjsonStr =String(data: jsondata, encoding:String.Encoding.utf8)else{
return
}
do{
tryjsonStr.write(toFile: jsonPath, atomically:true, encoding:String.Encoding.utf8)
}catch{
print("************ jsonStr写入失败 ************");
}
读取
guard let jsonData =NSData(contentsOfFile: jsonPath) else {
print("************ jsonStr读取失败 ************");
return
}
guard let jsonStr2 =String(data: jsonData as Data, encoding:String.Encoding.utf8) else {
return
}