let path = Bundle.main.path(forResource: "LiteratureModel", ofType: ".json")
// let url = URL(fileURLWithPath: path!)
// do {
// let data = try Data(contentsOf: url)
// let jsonDic:Dictionary<String,Any> = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<String, Any>
// let m: YXLiteratureTotalModel = Mapper<YXLiteratureTotalModel>().map(JSON: jsonDic)!
// self.literatureCurrentModel = m;
//
// } catch let error as Error? {
// print("读取本地数据出现错误!",error as Any)
// }
其中YXLiteratureTotalModel.swift
import UIKit
import ObjectMapper
class YXLiteratureTotalModel: Mappable {
var note:String?
var category: String?
var topic: String?
required init?(map: Map) {}
func mapping(map: Map) {
note <- map["note"]
category <- map["category"]
topic <- map["topic"]
}
}
swift加载本地json文件
最新推荐文章于 2024-05-31 13:33:28 发布