-1

我试图从特定玩家那里获取一些变量,然后将它们存储在数组中以操纵和显示它们,我将键放在数组上没有任何问题,但是在将字典的值放在返回获取用户数据它不允许我将它们存储在数组中

它显示Cannot convert from 'string[]' to ' PlayFabClientModels.UserDataRecord[]'

private String[] qDataKeys;
private String[] qDataValues;

void GetQuestionsData()
{
    PlayFabClientAPI.GetUserData(new GetUserDataRequest()
    {
        PlayFabId = "someID",
        Keys = null
    }, 
    OnQuestionsDataReceived, 
    OnError
    );
    
}

void OnQuestionsDataReceived(GetUserDataResult result)
{

    result.Data.Keys.CopyTo(qDataKeys, 0);
    result.Data.Values.CopyTo(qDataValues, 0);// This is the one that gives the error, above one is okay
}
4

1 回答 1

0

错误中的问题非常清楚。此调用返回的类型是 type PlayFabClientModels.UserDataRecord[]。查看文档,UserDataRecord 类型设置为

Ordered by:
Data name
Data type
Data Description

LastUpdated 
string
Timestamp for when this data was last updated.

Permission  
UserDataPermission
Indicates whether this data can be read by all users (public) or only the user (private). This is used for GetUserData requests being made by one player about another player.

Value   
string
Data stored for the specified user data key.

我假设你想要Value唱片的内部。我不确定您当前是如何访问的Key,因为文档指定GetUserDataResult返回Data的类型UserDataRecordDataVersion类型number

该错误当前告诉您copyTo您正在使用的 失败,因为当前类型是PlayFabClientModels.UserDataRecord[]并且您期望string[]. 您需要遍历每个索引并从每个索引中UserDataRecord获取数据。Value

我相信类似的东西

string[] yourData = result.Data.Value.Select(x => x.Value).ToArray();

应该管用。您将需要包含using System.Linq在文件的顶部。如果它不起作用,我只需要知道的类型,result.Data.Values但由于错误,我假设它是一个无数的数据数组。我不熟悉 PlayFab,因此如果当前文档已过时,请在评论中纠正我,我会尝试更新答案。

于 2021-04-20T20:21:21.613 回答