问题
I have this code:
let subjectAbbreviation = JSON?["data"]??["subject"]??["abbr"] as? String
Swift 3 complains:
Type Any has no subscript members
How would I unwrap this? I know I can use (JSON as? AnyObject) seems kind of messy though.
回答1:
You need to specify the type of your json to [String: Any] so try like this.
if let jsondata = json as? [String: Any], let data = jsondata["data"] as? [String: Any], let subject = data["subject"] as? [String: Any], let addr = subject["subject"] as? String {
print(addr)
}
来源:https://stackoverflow.com/questions/39740847/type-any-has-no-subscript-members-json-swift-3