更新时间:2023-02-03 14:26:14
我解决了我的问题,转换到正确的类型的原始NSDictionary值后我意识到不是NSDictionary的所有值都是NSStrings。如果您的服务返回类似于此的混合类型JSON对象
I solved my problem with casting to the correct type of the original NSDictionary value after i realised that not all values of the NSDictionary were NSStrings. If your service returns a mixed type JSON object like this
{"id":2, "name":"AC Vent Temp", ...}
你必须获取这样的值。
var id:int = sensor.valueForKey("id") as Int;
var name:String? = sensor.valueForKey("name") as String;