【发布时间】:2019-09-30 13:29:45
【问题描述】:
我有一些来自服务器的数据,我正在使用Alamofire SwiftyJSON 将其转换为[String: Any]。然后我使用SwiftyPlistManager 将其保存到 plist。重点是SwiftyPlistManager在保存<null>的时候崩溃了,所以我需要把<null>或者nil全部替换成""。
Alamofire SwiftyJSON 之后的我的字典是这样的:
["info_editable": true,
"name": Android Q,
"is_message": true,
"images": [["id": 92,
"image": /media/product/102.png]],
"video_description": <null>,
"is_valid": true]
或者它可能是-
["info_editable": true,
"name": Android Q,
"is_message": true,
"images": <null>,
"video_description": <null>,
"is_valid": true]
我想从原始数据中使用Codable,但不知道如何将初始值设置为空字符串或[[]],然后检查parced数据是否为<null>并将初始值保留为默认值。
或者有没有办法列出嵌套字典来替换<null>to ""?
【问题讨论】:
-
var updatedDictionary = Dictionary(uniqueKeysWithValues: yourDictionary.map { ($0, $1 != nil ? $1! : "") })
标签: swift swifty-json codable