无法转换'[String: String?]类型的值?[NSObject: AnyObject] " [NSObject: AnyObject] "

时间:2021-09-18 15:21:11

When I use Parse 1.8.5 to upload data to Parse, this cloud code has compile error in "params" that I cannot debug it.

当我使用Parse 1.8.5上载数据进行解析时,这个云代码在“params”中出现了编译错误,我无法对其进行调试。

       let params = ["phoneNumber" : userPhoneNumber, 
                    "username": username,
                    "password": userPassword,
                    "Email": userEmail
                     ]  

        PFCloud.callFunctionInBackground("sendCode", withParameters: params, block: 
              { (response: AnyObject?, error: NSError?) -> Void in
            if response?.localizedDescription != nil {
                print(error)
                var alert = UIAlertView(title: "Failure", message: "SignUp Error", delegate: self, cancelButtonTitle: "OK")
                alert.show()
            } else {
                self.activityIndicator.stopAnimating()
            }
        })

4 个解决方案

#1


16  

The error message says that there are optional types in the values of params.
Make sure that all values are unwrapped.

错误消息说参数的值中有可选类型。确保所有值都是未包装的。

#2


1  

I had the Same Problem in my project. i just changed my code from let parameters = ["email": mail,"password":passCode ] to let parameters = ["email": mail as! AnyObject,"password":passCode as! AnyObject] . Not sure if it affects anything else.

我的项目也有同样的问题。我刚把我的代码从let parameters = ["email": mail,"password":passCode改为let parameters = ["email": mail as!AnyObject,“密码”:密码!AnyObject]。不确定它是否影响到其他东西。

#3


0  

It works for me.Try this:

它适合我。试试这个:

let parameters = ["number": number, 
                  "username": username,
                  "password": userPassword,
                  "Email": userEmail]
PFCloud.callFunctionInBackground("sendCode", withParameters: parameters) { results, error in
            if error != nil {  
                 print(error)   
            } else {
                self.activityIndicator.stopAnimating() 
            }
}

Make sure number, username, userPassword, userEmail, sendCode are in the exact syntax in Parse Cloud

确保数字、用户名、用户密码、用户电子邮件和sendCode在解析云中的语法是正确的

#4


0  

Try this on to cast each element to AnyObject

尝试将每个元素强制转换为AnyObject

    let params = ["phoneNumber" : userPhoneNumber as! AnyObject, 
                "username": username as! AnyObject,
                "password": userPassword as! AnyObject,
                "Email": userEmail as! AnyObject
                 ] 

#1


16  

The error message says that there are optional types in the values of params.
Make sure that all values are unwrapped.

错误消息说参数的值中有可选类型。确保所有值都是未包装的。

#2


1  

I had the Same Problem in my project. i just changed my code from let parameters = ["email": mail,"password":passCode ] to let parameters = ["email": mail as! AnyObject,"password":passCode as! AnyObject] . Not sure if it affects anything else.

我的项目也有同样的问题。我刚把我的代码从let parameters = ["email": mail,"password":passCode改为let parameters = ["email": mail as!AnyObject,“密码”:密码!AnyObject]。不确定它是否影响到其他东西。

#3


0  

It works for me.Try this:

它适合我。试试这个:

let parameters = ["number": number, 
                  "username": username,
                  "password": userPassword,
                  "Email": userEmail]
PFCloud.callFunctionInBackground("sendCode", withParameters: parameters) { results, error in
            if error != nil {  
                 print(error)   
            } else {
                self.activityIndicator.stopAnimating() 
            }
}

Make sure number, username, userPassword, userEmail, sendCode are in the exact syntax in Parse Cloud

确保数字、用户名、用户密码、用户电子邮件和sendCode在解析云中的语法是正确的

#4


0  

Try this on to cast each element to AnyObject

尝试将每个元素强制转换为AnyObject

    let params = ["phoneNumber" : userPhoneNumber as! AnyObject, 
                "username": username as! AnyObject,
                "password": userPassword as! AnyObject,
                "Email": userEmail as! AnyObject
                 ]