jsdw_ios/QuickLocation/Manager/App/FileTools.swift

29 lines
806 B
Swift

//
// FileTools.swift
// SHECommunity
//
// Created by Lin on 2024/12/9.
//
import UIKit
class FileTools: NSObject {
/// json
static func readJSONFromFile(fileName: String) -> [String: Any]? {
if let fileURL = Bundle.main.url(forResource: fileName, withExtension: "json") {
do {
let jsonData = try Data(contentsOf: fileURL)
let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: [])
if let jsonDictionary = jsonObject as? [String: Any] {
// JSON
return jsonDictionary
}
} catch {
print("读取 JSON 文件发生错误: \(error)")
}
}
return nil
}
}