我已经打印了我想要获得的值,就像这样:
a = Optional(<__NSArrayM 0x1704494b0>(9))
如何提取值9?
我写了这个但是错了:let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count")
答案 0 :(得分:1)
试试这个: -
guard let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count"), let value = a.first else {return}
let stringValue = String(value)
print(stringValue)
答案 1 :(得分:0)
使用Swift本机类型和密钥/索引订阅
if let dict = parseJSON[index] as? [String:Any],
let subjectsCount = dict["subjects_count"] as? [Int], !subjectsCount.isEmpty {
print(subjectsCount[0])
}