美文网首页
iOS 加载.json.plist文件

iOS 加载.json.plist文件

作者: 五彩的石头 | 来源:发表于2020-09-07 14:28 被阅读0次
    加载json和plist资源

    加载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}

    记录一下吧防止再踩同样的坑!

    相关文章

      网友评论

          本文标题:iOS 加载.json.plist文件

          本文链接:https://www.haomeiwen.com/subject/yqnkektx.html