|
@@ -28,15 +28,22 @@ class KMLightMemberCache: NSObject {
|
|
}
|
|
}
|
|
|
|
|
|
//获取有用的参数
|
|
//获取有用的参数
|
|
- let dic: NSMutableDictionary = [:]
|
|
|
|
- for key in data.allKeys {
|
|
|
|
- let object = data.object(forKey: key)
|
|
|
|
- if ( !(object is NSNull)) {
|
|
|
|
- dic.setObject(object as Any, forKey: key as! NSCopying)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// let dic: NSMutableDictionary = [:]
|
|
|
|
+// for key in data.allKeys {
|
|
|
|
+// let object = data.object(forKey: key)
|
|
|
|
+// if let subDictionary = object as? [NSDictionary] {
|
|
|
|
+//
|
|
|
|
+// } else if (!(object is NSNull)) {
|
|
|
|
+// dic.setObject(object as Any, forKey: key as! NSCopying)
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
|
|
- let saveData: NSArray = [dic]
|
|
|
|
|
|
+// let dic: [String: Any] = data.allKeys // 待处理的字典数据
|
|
|
|
+ let result = removeNullValuesFromDictionary(data as! [String : Any])
|
|
|
|
+
|
|
|
|
+// dic.removeObject(forKey: "subscriptionInfoList")
|
|
|
|
+
|
|
|
|
+ let saveData: NSArray = [result]
|
|
let success = saveData.write(toFile: string.expandingTildeInPath as String, atomically: true)
|
|
let success = saveData.write(toFile: string.expandingTildeInPath as String, atomically: true)
|
|
|
|
|
|
if (success == true) {
|
|
if (success == true) {
|
|
@@ -64,3 +71,36 @@ class KMLightMemberCache: NSObject {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+extension KMLightMemberCache {
|
|
|
|
+ /**
|
|
|
|
+ */
|
|
|
|
+ func removeNullValuesFromDictionary(_ dictionary: [String: Any]) -> [String: Any] {
|
|
|
|
+ var result: [String: Any] = [:]
|
|
|
|
+
|
|
|
|
+ for (key, value) in dictionary {
|
|
|
|
+ if let subDictionary = value as? [NSDictionary] {
|
|
|
|
+ // 子集为数组,则递归遍历子字典并进行处理
|
|
|
|
+ var array: [Any] = []
|
|
|
|
+ for item in subDictionary {
|
|
|
|
+ let cleanedSubDictionary = removeNullValuesFromDictionary(item as! [String : Any])
|
|
|
|
+ array.append(cleanedSubDictionary)
|
|
|
|
+ }
|
|
|
|
+ if !array.isEmpty {
|
|
|
|
+ result[key] = array
|
|
|
|
+ }
|
|
|
|
+ } else if let subDictionary = value as? [String: Any] {
|
|
|
|
+ // 子集为字典,则递归遍历子字典并进行处理
|
|
|
|
+ let cleanedSubDictionary = removeNullValuesFromDictionary(subDictionary)
|
|
|
|
+ if !cleanedSubDictionary.isEmpty {
|
|
|
|
+ result[key] = cleanedSubDictionary
|
|
|
|
+ }
|
|
|
|
+ } else if !(value is NSNull) {
|
|
|
|
+ // 子集不为 null,则将键值对添加到结果字典中
|
|
|
|
+ result[key] = value
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result
|
|
|
|
+ }
|
|
|
|
+}
|