gpt4 book ai didi

ios - 无法将类型 'NSDictionary' 的值转换为指定类型 'Dictionary'

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:55:53 24 4
gpt4 key购买 nike

为什么这是可能的:

var orderRequestUserValues : Dictionary  = [ "ClientID": "TEST",
"UserName": "sysadmin",
"Password": "123456",
"ModuleID": "StockProcessing",
"FunctionID": "SetStockActivity",
"TransmissionFlags": 32,
"TransmissionMethod": 5
]

但这不是:

let userName : String = (dataSourceForUserInfo.last?.UserName)!
let password : String = (dataSourceForUserInfo.last?.Password)!
let clientID : String = (dataSourceForUserInfo.last?.ClientID)!
var orderRequestUserValues : Dictionary = [ "ClientID": "\(clientID)",
"UserName": "\(userName)",
"Password": "\(password)",
"ModuleID": "StockProcessing",
"FunctionID": "SetStockOrder",
"TransmissionFlags": 32,
"TransmissionMethod": 5


]

出现错误:无法将“NSDictionary”类型的值转换为指定类型“Dictionary”

我需要它像这样工作,因为我必须像这样向它附加数据:

orderRequestUserValues.updateValue(requestParameters, forKey: "RequestParameters")

最佳答案

这应该是你想要的

var orderRequestUserValues : [String : Any]  = [
"ClientID": "TEST",
"UserName": "sysadmin",
"Password": "123456",
"ModuleID": "StockProcessing",
"FunctionID": "SetStockActivity",
"TransmissionFlags": 32,
"TransmissionMethod": 5
]

这也适用于字符串插值:

var orderRequestUserValues : [String : Any]  = [
"ClientID": "\(clientID)",
"UserName": "\(userName)",
"Password": "\(password)",
"ModuleID": "StockProcessing",
"FunctionID": "SetStockOrder",
"TransmissionFlags": 32,
"TransmissionMethod": 5
]

还要注意,如果字典是不可变的,您可以使用 let 而不是 var

关于ios - 无法将类型 'NSDictionary' 的值转换为指定类型 'Dictionary',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40413365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com