加载json
1. guard let ruUrl = Bundle.main.url(forResource:"ru", withExtension:"json") else {return}
2. guard let ruData = try? Data(contentsOf: ruUrl) else {return}
3. guard let ruDict =try? JSONSerialization.jsonObject(with: ruData, options:.mutableLeaves) else {return}
加载plist
1. guard let dePath = Bundle.main.path(forResource:"de", ofType:"plist") else {return}
2. guard let deDict = NSDictionary(contentsOfFile: dePath) else {return}
本地文件夹加载文件夹中的json
1. let jsonPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] + "/LocalLanguage" + "/ru.json"
2. guard let data = FileManager.default.contents(atPath: jsonPath) else {return}
3. guard let ruDict = try?JSONSerialization.jsonObject(with: data, options:.mutableLeaves) else {return}
记录一下吧防止再踩同样的坑!
网友评论