首页 > 代码库 > swift3.0 存取json数据到沙盒
swift3.0 存取json数据到沙盒
do {
//将json保存到本地
let jsonData = http://www.mamicode.com/try JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)
// here "jsonData" is the dictionary encoded in JSON data
let data = http://www.mamicode.com/jsonData as NSData
data.write(toFile: filePath, atomically: true)
//构建文件路径
let filePath:String = NSHomeDirectory() + "/Documents/imagetovideo.json"
//读取json
var loaddata=http://www.mamicode.com/NSData(contentsOfFile: filePath)
if loaddata != nil
{
let jData=http://www.mamicode.com/loaddata as! Data
let decoded = try JSONSerialization.jsonObject(with: jData, options: [])
print("译码:",decoded)
}
} catch {
print(error.localizedDescription)
}
swift3.0 存取json数据到沙盒