0
我已經印刷,我想是這樣的值:提取值從__NSArrayM
a = Optional(<__NSArrayM 0x1704494b0>(9))
我如何提取價值9? 我寫了這一點,但錯誤的是:let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count")
我已經印刷,我想是這樣的值:提取值從__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])
}
它的工作原理!非常感謝 – Marco
我該如何將它轉換爲字符串? – Marco
我修改了代碼,包括類型轉換爲字符串 –