📜  从 url 快速读取 json - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:48.895000             🧑  作者: Mango

代码示例1
private func readLocalFile(forName name: String) -> Data? {
    do {
        if let bundlePath = Bundle.main.path(forResource: name,
                                             ofType: "json"),
            let jsonData = try String(contentsOfFile: bundlePath).data(using: .utf8) {
            return jsonData
        }
    } catch {
        print(error)
    }
    
    return nil
}