KMJSONParser.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // KMJSONParser.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2022/12/21.
  6. //
  7. import Cocoa
  8. enum KMParseOutType : Int {
  9. case Json = 1 // json字符串格式
  10. case ArrayObj // 数组盛放对象格式
  11. case ArrayDict // 数组盛放字典格式
  12. }
  13. protocol KMJSONParserDelegate {
  14. func parser(_ parser: KMJSONParser, success responseObj: Any)
  15. }
  16. class KMJSONParser: NSObject {
  17. var delete: KMJSONParserDelegate? // 回调处理
  18. var parseFilePaths: [String]? // 等待解析的文件路径
  19. var parseOutType: KMParseOutType = .ArrayObj // 解析后数据的输出类型
  20. var aliasLightParse: KMAliasLightParser = KMAliasLightParser.init()
  21. var compLightParse: KMCompLightParser = KMCompLightParser.init()
  22. var globalParse: KMGlobalParser = KMGlobalParser.init()
  23. var colArr: [Any]?
  24. var globalDict: [String : Any] = [:]
  25. var aliasLightDict: [String : Any] = [:]
  26. var compLigntDict: [String : Any] = [:]
  27. var globalModel = KMGlobal.init()
  28. var aliasLightModel = KMAliasLight.init()
  29. var compLigntModel = KMCompLight.init()
  30. static let defaultJSONParser_JSONParser: KMJSONParser? = {
  31. var jsonParser = KMJSONParser()
  32. return jsonParser
  33. }()
  34. class func defaultJSONParser() -> Self {
  35. return defaultJSONParser_JSONParser as! Self
  36. }
  37. func parse() -> Void {
  38. // DispatchQueue.global().async {
  39. // 解析 comp-lignt.json 文件
  40. self.globalDict = self.parseGlobal()
  41. self.aliasLightDict = self.parseAliasLight()
  42. self.compLigntDict = self.parseCompLight()
  43. self.compLightParse.parserValueNode(self.compLigntDict, "")
  44. self.delete?.parser(self, success: self.compLightParse.finalDict)
  45. // }
  46. }
  47. func parseCompLight() -> [String : Any] {
  48. compLightParse.globalDict = globalDict
  49. compLightParse.aliasLightDict = aliasLightDict
  50. return compLightParse.startJSONParse()
  51. }
  52. func parseAliasLight() -> [String : Any] {
  53. aliasLightParse.globalDict = globalDict
  54. return aliasLightParse.startJSONParse()
  55. }
  56. func parseGlobal() -> [String : Any] {
  57. return globalParse.startJSONParse()
  58. }
  59. // MARK: Find
  60. // func findKeyValue(withKey: String) -> KMCompLight_UIValue {
  61. // compLightParse.
  62. // return
  63. // }
  64. }