123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- //
- // KMJSONParser.swift
- // PDF Master
- //
- // Created by wanjun on 2022/12/21.
- //
- import Cocoa
- enum KMParseOutType : Int {
- case Json = 1 // json字符串格式
- case ArrayObj // 数组盛放对象格式
- case ArrayDict // 数组盛放字典格式
- }
- protocol KMJSONParserDelegate {
- func parser(_ parser: KMJSONParser, success responseObj: Any)
- }
- class KMJSONParser: NSObject {
- var delete: KMJSONParserDelegate? // 回调处理
- var parseFilePaths: [String]? // 等待解析的文件路径
- var parseOutType: KMParseOutType = .ArrayObj // 解析后数据的输出类型
- var aliasLightParse: KMAliasLightParser = KMAliasLightParser.init()
- var compLightParse: KMCompLightParser = KMCompLightParser.init()
- var globalParse: KMGlobalParser = KMGlobalParser.init()
- var colArr: [Any]?
-
- var globalDict: [String : Any] = [:]
- var aliasLightDict: [String : Any] = [:]
- var compLigntDict: [String : Any] = [:]
- var globalModel = KMGlobal.init()
- var aliasLightModel = KMAliasLight.init()
- var compLigntModel = KMCompLight.init()
-
- static let defaultJSONParser_JSONParser: KMJSONParser? = {
- var jsonParser = KMJSONParser()
- return jsonParser
- }()
-
- class func defaultJSONParser() -> Self {
- return defaultJSONParser_JSONParser as! Self
- }
-
- func parse() -> Void {
- // DispatchQueue.global().async {
- // 解析 comp-lignt.json 文件
- self.globalDict = self.parseGlobal()
- self.aliasLightDict = self.parseAliasLight()
- self.compLigntDict = self.parseCompLight()
-
- self.compLightParse.parserValueNode(self.compLigntDict, "")
- self.delete?.parser(self, success: self.compLightParse.finalDict)
- // }
- }
-
- func parseCompLight() -> [String : Any] {
- compLightParse.globalDict = globalDict
- compLightParse.aliasLightDict = aliasLightDict
- return compLightParse.startJSONParse()
- }
-
- func parseAliasLight() -> [String : Any] {
- aliasLightParse.globalDict = globalDict
- return aliasLightParse.startJSONParse()
- }
-
- func parseGlobal() -> [String : Any] {
- return globalParse.startJSONParse()
- }
-
- // MARK: Find
-
- // func findKeyValue(withKey: String) -> KMCompLight_UIValue {
- // compLightParse.
- // return
- // }
- }
|