标签:desc 本地 ati data catch erro content write pre
do {
//将json保存到本地
let jsonData = try JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)
// here "jsonData" is the dictionary encoded in JSON data
let data = jsonData as NSData
data.write(toFile: filePath, atomically: true)
//构建文件路径
let filePath:String = NSHomeDirectory() + "/Documents/imagetovideo.json"
//读取json
var loaddata=NSData(contentsOfFile: filePath)
if loaddata != nil
{
let jData=loaddata as! Data
let decoded = try JSONSerialization.jsonObject(with: jData, options: [])
print("译码:",decoded)
}
} catch {
print(error.localizedDescription)
}
标签:desc 本地 ati data catch erro content write pre
原文地址:http://www.cnblogs.com/payne1991/p/7219082.html