从 __NSArrayM 中提取值

Extract value from __NSArrayM

我打印了我想要得到的值,是这样的:

a =  Optional(<__NSArrayM 0x1704494b0>(9))

如何提取值 9? 我写了这个但是错了:let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count")

试试这个:-

guard let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count"), let value = a.first else {return}
let stringValue = String(value)
print(stringValue)

使用Swift原生类型和键/索引订阅

if let dict = parseJSON[index] as? [String:Any],
   let subjectsCount = dict["subjects_count"] as? [Int], !subjectsCount.isEmpty {
   print(subjectsCount[0])
}