![](/img/trans.png)
[英]Is there a sane way to parse a nested JSON with unknown structure into an object or a dictionary in Swift 5?
[英]Replace SWIFT dictionary into JSON object
我正在尝试从 SwiftyJSON 的 JSON 对象中的字典中删除一个元素。 我尝试将元素转换为字典,删除元素并替换回如下:
var testJSON = JSON(["Item1":["1":"1","2":"2","3":"3"],"Item2":"Value2","Item3":"Value3","Item4":"Value4"])
// convert to dictionary
var jsonDict: [String:JSON] = testJSON["Item1"].dictionaryValue
// remove element
jsonDict.removeValueForKey("1")
// replace into original
testJSON["Item1"].dictionary = jsonDict
但我收到这个错误
错误:无法将 [String:JSON] 分配给 [String:JSON] 类型的值?
我究竟做错了什么? 谢谢
您正在尝试将可选分配给非可选。
.jsonvalue
返回一个可选的。 首先打开它确保它没有返回nil
然后将它分配给字典。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.