使用XCode8上传Swift3时遇到以下错误.
I've encountered following error while uploading Swift3 using XCode8.
'NSInvalidArgumentException',原因:'JSON写入中的类型无效 (_SwiftValue)'
'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)'
let param: Parameters = [ "email":txrNRC.text as AnyObject, "password":txtPassword.text as AnyObject ]
请让我知道如何解决该问题.我已经尝试使用let param: NSDictionary,但收到了相同的错误消息.
Please let me know how to solve that issue. I've already tried with let param: NSDictionary but got same error message.
推荐答案首先,在Swift 3中,id的Objective-C等效项是Any而不是AnyObject,这也避免了AnyObject强制转换
First of all in Swift 3 the Objective-C equivalent of id is Any rather than AnyObject, that avoids also the AnyObject castings.
错误消息表明使用了非法类型(Parameters),JSON仅支持string,number,<null>和array/dictionary.
The error message indicates that an illegal type is used (Parameters), JSON supports only string, number, <null> and array / dictionary.
如果您的词典是[String:String],则根本不需要类型注释
In your case the dictionary is [String:String], a type annotation is not needed at all
let param = [ "email" : txrNRC.text, "password" : txtPassword.text ]如果txrNRC和txtPassword是可选的,则您需要解开它们,或者如果值是nil
If txrNRC and txtPassword are optionals you need to unwrap them or use the nil coalescing operator to assign a placeholder if the value is nil
更多推荐
'NSInvalidArgumentException',原因:“带有Alamofire swift3的JSON写入(
发布评论