我最近创建了一个云代码函数,用于获取,编辑和保存名为“Friends”的字符串数组。它包含用户拥有的所有朋友的列表。该函数从该列表中删除指定的用户。出于某种原因,每当我尝试从swift代码运行它时,我都会收到错误:JSON文本没有以数组或对象开头,并且选项允许未设置片段。下面是函数和我正在使用的swift代码。我不确定为什么会发生这种情况,如果有人能帮助我,我会很感激。
云代码功能:
Parse.Cloud.define("removeFriend", function(request, response) {
var userObjId = request.params.userObjId;
var currentUser = request.params.currentUser
var query = new Parse.Query(Parse.User);
query.equalTo("objectId", userObjId);
query.find({
success: function(results){
var friends = results["Friends"];
for(var i in friends){
if(friends[i]==currentUser){
array.splice(i,1);
i--;
break;
}
}
results["Friends"] = friends;
results.save(null, {
useMasterKey: true
});
response.success("User successfully removed & saved.");
},
error: function(){
response.error("The user was not successfully removed.");
}
});
});
Swift Code:
PFCloud.callFunction(inBackground: "removeFriend", withParameters: ["userObjId": friendObjId, "currentUser": currentUser!], block: { (success, error) in
if error != nil{
print(error!, "ASDASDASDASDJLASDLASDKNASD")
}else{
print("Successfully removed user")
}
})