如何解决如何将 PlayFab 的 UserDataRecord 转换为字符串数组
我试图从特定玩家那里获取一些变量,然后将它们存储在数组中以操作和显示它们,将键放在数组上没有任何问题,但是在放置值的那一刻为获取用户数据返回的字典它不允许我将它们存储在数组中
显示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
}
解决方法
问题在错误中非常清楚。此调用返回的类型为 PlayFabClientModels.UserDataRecord[]
类型。检查 docs,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
类型为 UserDataRecord
和 DataVersion
number
类型。
错误当前告诉您您正在使用的 copyTo
失败,因为当前类型是 PlayFabClientModels.UserDataRecord[]
而您期望的是 string[]
。您需要遍历每个 UserDataRecord
并从每个索引中获取 Value
数据。
我相信一些东西
string[] yourData = result.Data.Value.Select(x => x.Value).ToArray();
应该可以。您需要在文件顶部包含 using System.Linq
。如果它不起作用,我只需要知道 result.Data.Values
的类型,但由于错误,我假设它是一个无数的数据数组。我不熟悉 PlayFab,因此如果当前文档已过时,请在评论中纠正我,我会尝试更新答案。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。