'NSInvalidArgumentException',原因:“带有Alamofire swift3的JSON写入(

编程入门 行业动态 更新时间:2024-10-27 09:41:01
本文介绍了'NSInvalidArgumentException',原因:“带有Alamofire swift3的JSON写入(_SwiftValue)中的无效类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用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写入(

本文发布于:2023-11-26 04:45:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632675.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原因   NSInvalidArgumentException   JSON   Alamofire

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!