I am trying to parse the JSON format as follows:
{ "key_1" : { "key_2" : "value" } }
and then assign the variable "value" variable.
Here is my code:
var variableShouldBeAssigned: String if let x = (jsonResult["key_1"]? as? NSDictionary) { if let y = (x["key_2"]? as? String) { variableShouldBeAssigned = y } }
However, an error occurs when I try to disconnect from x["key_2"]? to String, but is it fine to reset with jsonResult["key_1"]? in NSDictionary.
Can I solve this error using x["key_2"] to replace x["key_2"]? but I really don't know why it only works for jsonResult["key_1"]? .
Can someone tell me the reason?
source share