Parse.com错误:键'',预期数组的无效类型,但得到字符串(代码:111,版本:1.8.3)

时间:2021-02-23 17:02:14

I am using Parse framework in Swift. I have the following code

我在Swift中使用Parse框架。我有以下代码

var user = PFUser()
user.username = "username"
user.password = "password"
user.addObject("firstname", forKeyedSubscript: "firstName")
user.addObject("lastName", forKeyedSubscript: "lastName")
user.addObject("mobileNumber", forKeyedSubscript: "mobile")
user.addObject("city", forKeyedSubscript: "city")

user.signUpInBackgroundWithBlock { succeeded, error in
    if (succeeded) {
        //The registration was successful
    } else if let error = error {
        //Something bad has occurred
    }
}

In the web portal, it shows like this:

在Web门户中,它显示如下:

Parse.com错误:键'',预期数组的无效类型,但得到字符串(代码:111,版本:1.8.3)

It creates 'Array's in the columns with the keys I have given. I want them to be strings. So, I have changed my code to the following. So, I have changed addObject to setObject as following:

它使用我给出的键在列中创建“数组”。我希望他们成为字符串。所以,我已将代码更改为以下内容。所以,我已经将addObject更改为setObject,如下所示:

var user = PFUser()
user.username = "username"
user.password = "password"
user.setObject("firstname", forKeyedSubscript: "firstName")
user.setObject("lastName", forKeyedSubscript: "lastName")
user.setObject("mobileNumber", forKeyedSubscript: "mobile")
user.setObject("city", forKeyedSubscript: "city")

user.signUpInBackgroundWithBlock { succeeded, error in
    if (succeeded) {
        //The registration was successful
    } else if let error = error {
        //Something bad has occurred
    }
}

It shows the following error

它显示以下错误

[Error]: invalid type for key city, expected array, but got string (Code: 111, Version: 1.8.3)

How can I add strings in the columns with keys using Swift code ?

如何使用Swift代码在键中添加字符串?

2 个解决方案

#1


0  

You need to change column type for city, firstName, lastName and mobile to String on parse.com portal. You'll need to remove this columns and add new columns with same name and correct type.

您需要在parse.com门户上将city,firstName,lastName和mobile的列类型更改为String。您需要删除此列并添加具有相同名称和正确类型的新列。

#2


0  

The problem is that you have already created columns on this entity that are of different type than you want to set now.

问题是您已经在此实体上创建了与您现在要设置的类型不同的列。

Basing on amount of data in your database I suggest you to remove those columns. You have to do this using the Parse dashboard.

根据数据库中的数据量,我建议您删除这些列。您必须使用Parse仪表板执行此操作。

#1


0  

You need to change column type for city, firstName, lastName and mobile to String on parse.com portal. You'll need to remove this columns and add new columns with same name and correct type.

您需要在parse.com门户上将city,firstName,lastName和mobile的列类型更改为String。您需要删除此列并添加具有相同名称和正确类型的新列。

#2


0  

The problem is that you have already created columns on this entity that are of different type than you want to set now.

问题是您已经在此实体上创建了与您现在要设置的类型不同的列。

Basing on amount of data in your database I suggest you to remove those columns. You have to do this using the Parse dashboard.

根据数据库中的数据量,我建议您删除这些列。您必须使用Parse仪表板执行此操作。