爲什麼下面的代碼給我的錯誤:JSONSerialization無效類型的JSON寫(_SwiftValue)
Invalid type in JSON write (_SwiftValue).
錯誤是扔在這條線:
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters)
全碼:
let parameters:Parameters = ["resource":[
[
"appUserCode":uuidString,
"productNFCode": self.nfCode!,
"status":code,
"applicationKey":appDelegate.api_key
]
]
]
do {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters)
} catch {
// No-op
}
在我的情況下,每個關鍵值都沒問題仍然出現此錯誤@KrishnaCA –
@Mansuu ....請檢查是否有一個字符串是可選的,如下所示 – KrishnaCA