[英]Not able to access values from dictionary
我有一本這樣的字典..
{
"Due_Date" = "2020-06-09T15:00:13";
departmentID = 180075;
keyPointID = "";
id = 4;
jobID = 180093;
jobName = myLab;
plantID = 1232;
shiftID = 2;
"smat_Leader1ID" = 43232;
workshopID = 423423;
workstationID = 1892074;
}
除了鍵和值為字符串的值(如 Due_Date)之外,我無法獲得任何值。 我是這樣拿的...
var Due_Date = self.dictionary["Due_Date"]! as? String //This gives an answer
同樣,如果我嘗試獲取這些值,我不會得到這些值
var Department_ID = self.dictionary["departmentID"]! as? Int ?? 0 //This gives 0
var smatLeader1ID = self.dictionary["smat_Leader1ID"]! as? Int ?? 0 //This gives 0
(我也沒有得到其他值。只是我上面提到的 2)
由於您強制轉換並且沒有崩潰,因此您似乎獲得了價值,但您試圖將價值轉換為Int
在這里失敗。 似乎該值不是Int
類型可能是String
嘗試修復它。
替換這個:
var Department_ID = self.dictionary["departmentID"]! as? Int ?? 0
有了這個:
var Department_ID = Int(self.dictionary["departmentID"] as? String ?? "0")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.