如何从解析云函数将解析对象列表返回到 Unity

How do I return a list of ParseObjects to Unity from a Parse cloud function?

本文关键字:列表 返回 Unity 对象 函数      更新时间:2023-09-26

使用以下代码,我可以将单个排行榜分数返回给 Unity,但是我想做的是返回scoreResults并最终得到 Unity 中的排行榜分数列表

我不确定我需要在 Unity 方面指定什么类型才能实现这一目标。我假设它只是IDictionary<string,object>[],因为 Parse.Query.find 返回一个 ParseObjects 数组,但是当我这样做时t.IsFaulted是正确的,但没有打印错误消息或代码(我认为它可能在转换为 ParseException 时遇到一些问题)。

如果有人能阐明这里需要做什么,我将不胜感激:)

云代码

Parse.Cloud.define("getFriendsScores", function(request, response)
{
    // code to get friends
    var scoresQuery = new Parse.Query("LeaderboardScore");
    scoresQuery.containedIn("user", parseFriends);
    scoresQuery.find(
    {
        success: function(scoreResults)
        {
            response.success(scoreResults[0]);
        },
        error: function(scoreError)
        {
            console.log('No matching scores found...');
        }
    });
}

统一代码

ParseCloud.CallFunctionAsync<IDictionary<string, object>>("getFriendsScores", parameters).ContinueWith(t =>
{
    if (t.IsFaulted)
    {
        foreach (var e in t.Exception.InnerExceptions)
        {
            ParseException parseException = e as ParseException;
            Debug.Log("Error message " + parseException.Message);
            Debug.Log("Error code: " + parseException.Code);
        }
    }
    else
    {
        Debug.Log("Success!");
    }
});

设法通过在 Unity 中使用以下类型使其工作:

<IList<IDictionary<string, object>>>

单个 ParseObject 作为实现 IDictionary<string, object> 的对象返回,当您请求列表时,它会为您提供这些列表的列表(我只是使用 IList,因为它更通用)。

对于其他任何努力弄清楚这些函数的返回类型的人,只需做这样的事情,你就会解决它:

ParseCloud.CallFunctionAsync<object>("functionName", parameters).ContinueWith(t =>
{
    Debug.Log(t.Result.GetType().ToString());
}