2017-07-30 56 views
0

我已經印刷,我想是這樣的值:提取值從__NSArrayM

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

我如何提取價值9? 我寫了這一點,但錯誤的是:let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count")

回答

1

試試這個: -

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

它的工作原理!非常感謝 – Marco

+0

我該如何將它轉換爲字符串? – Marco

+0

我修改了代碼,包括類型轉換爲字符串 –

0

使用SWIFT原生類型和主鍵/索引訂閱

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